Skip to content

Commit 78c0b23

Browse files
author
Dan Ryan
committed
update to be compatible with Chef 0.10 API
1 parent 3e50fe4 commit 78c0b23

File tree

7 files changed

+422
-8
lines changed

7 files changed

+422
-8
lines changed

Gemfile

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ gem 'yajl-ruby'
66

77
group :development, :test do
88
gem "yard", "~> 0.6.4"
9-
gem "rspec", "~> 2.5.0"
10-
gem "cucumber", "~> 0.10.0"
11-
gem "webmock", "~> 1.6.2"
12-
gem "timecop", "~> 0.3.5"
13-
gem 'watchr'
14-
gem 'spork', '~> 0.9.0.rc'
15-
gem 'webmock', '~> 1.6.2'
9+
gem 'rspec', '>= 2.6.0'
10+
gem "webmock", ">= 1.6.2"
11+
gem "timecop", ">= 0.3.5"
12+
gem 'guard', '>= 0.6.2'
13+
gem 'guard-rspec', '>= 0.4.2'
14+
gem 'guard-spork', '>= 0.2.1'
15+
gem 'spork', '>= 0.9.0.rc8'
16+
gem 'rb-fsevent', '>= 0.4.3.1'
17+
gem 'growl', '>= 1.0.3'
1618
end

Guardfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
guard 'rspec', :version => 2, :cli => "--format documentation" do
2+
watch(%r{^spec/.+_spec\.rb$})
3+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4+
watch('spec/spec_helper.rb') { "spec" }
5+
end
6+
7+
guard 'spork' do
8+
watch('spec/spec_helper.rb')
9+
end

lib/spice.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require 'spice/cookbook'
1414
require 'spice/data_bag'
1515
require 'spice/node'
16+
require 'spice/environment'
1617
require 'spice/search'
1718
require 'spice/connection'
1819

lib/spice/environment.rb

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module Spice
2+
class Environment < Spice::Chef
3+
# Get a list of all data bags in the following syntax
4+
# Spice::Environment.all
5+
#
6+
# @param [Hash] options the options hash. Currently does nothing
7+
def self.all(options={})
8+
connection.get("/environments")
9+
end
10+
11+
# An alternative format for showing the contents of a data bag
12+
# @example Retrieve the id and uri of items in a data bag called "users"
13+
# Spice::Environment["users"] # => {"adam":"http://localhost:4000/data/users/adam"}
14+
def self.[](name)
15+
connection.get("/environments/#{name}")
16+
end
17+
18+
# Show the contents of a data bag
19+
# @example Retrieve the id and uri of items in a data bag called "users"
20+
# Spice::Environment.show(:name => "users") # => {"adam":"http://localhost:4000/data/users/adam"}
21+
#
22+
# @param [Hash] options The options hash
23+
# @option options [String] :name The name of your data bag
24+
def self.show(options={})
25+
raise ArgumentError, "Option :name must be present" unless options[:name]
26+
name = options.delete(:name)
27+
connection.get("/environments/#{name}")
28+
end
29+
30+
# Create a a new data bag
31+
#
32+
# @example
33+
# Spice::Environment.create(:name => "users")
34+
#
35+
# @param [Hash] options the options hash from which to create a data bag
36+
# @option options [String] :name The name of your data bag
37+
38+
def self.create(options={})
39+
options[:chef_type] ||= "environment"
40+
options[:json_class] ||= "Chef::Environment"
41+
options[:attributes] ||= {}
42+
options[:description] ||= ""
43+
options[:cookbook_versions] ||= {}
44+
connection.post("/environments", options)
45+
end
46+
47+
# Delete a data bag
48+
#
49+
# @example
50+
# Spice::Environment.delete(:name => "users")
51+
#
52+
# @param [Hash] options the options hash from which to delete a data bag
53+
# @option options [String] :name The name of your data bag
54+
55+
def self.delete(options={})
56+
raise ArgumentError, "Option :name must be present" unless options[:name]
57+
name = options.delete(:name)
58+
connection.delete("/environments/#{name}", options)
59+
end
60+
61+
# Shows a data bag item
62+
#
63+
# @example
64+
# Spice::Environment.show_item(:name => "users", :id => "adam")
65+
#
66+
# @param [Hash] options the options hash from which to create a data bag
67+
# @option options [String] :name The name of your data bag
68+
# @option options [String] :id The id of the data bag item
69+
70+
def self.show_cookbook(options={})
71+
raise ArgumentError, "Option :name must be present" unless options[:name]
72+
raise ArgumentError, "Option :cookbook must be present" unless options[:cookbook]
73+
name = options.delete(:name)
74+
cookbook = options.delete(:cookbook)
75+
connection.get("/environments/#{name}/cookbooks/#{cookbook}", options)
76+
end
77+
78+
def self.list_cookbooks(options={})
79+
raise ArgumentError, "Option :name must be present" unless options[:name]
80+
name = options.delete(:name)
81+
connection.get("/environments/#{name}/cookbooks", options)
82+
end
83+
84+
end
85+
end

lib/spice/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Spice
2-
VERSION = "0.5.0"
2+
VERSION = "0.6.0"
33
end

spec/spice/environment_spec.rb

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
require 'spec_helper'
2+
3+
module Spice
4+
describe Environment do
5+
describe ".all" do
6+
before { stub_environment_list }
7+
subject { Environment.all }
8+
9+
it { should have_body(environment_list_response) }
10+
it { should respond_with(200) }
11+
end
12+
13+
describe ".show" do
14+
context "if the environment is found" do
15+
before { stub_environment_show }
16+
subject { Environment.show(:name => "dev") }
17+
18+
it { should have_body(environment_show_response) }
19+
it { should respond_with(200) }
20+
end
21+
22+
context "if the environment is not found" do
23+
before { stub_environment_show(404) }
24+
subject { Environment.show(:name => "dev") }
25+
26+
it { should_not have_body(environment_show_response) }
27+
it { should respond_with(404) }
28+
end
29+
end
30+
31+
describe ".create" do
32+
context "if the environment can be created" do
33+
before { stub_environment_create }
34+
subject { Environment.create(:name => "dev") }
35+
36+
it { should have_body(environment_create_response) }
37+
it { should respond_with(201) }
38+
end
39+
40+
context "if the environment already exists" do
41+
before { stub_environment_create(409) }
42+
subject { Environment.create(:name => "dev") }
43+
44+
it { should have_body(environment_conflict) }
45+
it { should respond_with(409) }
46+
end
47+
end
48+
49+
describe ".delete" do
50+
context "if the environment can be deleted" do
51+
before { stub_environment_delete }
52+
subject { Environment.delete(:name => "dev") }
53+
54+
it { should have_body(environment_delete_response) }
55+
it { should respond_with(200) }
56+
end
57+
58+
context "if the environment cannot be deleted" do
59+
before { stub_environment_delete(404) }
60+
subject { Environment.delete(:name => "dev") }
61+
62+
it { should have_body(environment_not_found) }
63+
it { should respond_with(404) }
64+
end
65+
end
66+
67+
describe ".list_cookbooks" do
68+
context "if cookbooks exists" do
69+
before { stub_environment_cookbooks_list }
70+
subject { Environment.list_cookbooks(:name => "dev") }
71+
72+
it { should have_body(environment_cookbooks_list_response) }
73+
it { should respond_with(200) }
74+
end
75+
end
76+
77+
describe ".show_cookbook" do
78+
context "if the cookbook exists" do
79+
before { stub_environment_cookbook_show }
80+
subject { Environment.show_cookbook(:name => "dev", :cookbook => "apache") }
81+
82+
it { should have_body(environment_cookbook_show_response) }
83+
it { should respond_with(200) }
84+
end
85+
86+
context "if the cookbook does not exist" do
87+
before { stub_environment_cookbook_show(404) }
88+
subject { Environment.show_cookbook(:name => "dev", :cookbook => "apache") }
89+
90+
it { should have_body(environment_not_found) }
91+
it { should respond_with(404) }
92+
end
93+
end
94+
95+
end
96+
end

0 commit comments

Comments
 (0)