1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
require File.join(File.dirname(__FILE__), "..", 'spec_helper.rb')
describe OpenidRegister, "index action" do
it "should get a list of all registered nodes" do
Chef::OpenIDRegistration.should_receive(:list).with(true).and_return(["one"])
dispatch_to(OpenidRegister, :index) do |c|
c.stub!(:display)
end
end
end
describe OpenidRegister, "show action" do
it "should raise a 404 if the nodes registration is not found" do
Chef::OpenIDRegistration.should_receive(:load).with("foo").and_raise(RuntimeError)
lambda {
dispatch_to(OpenidRegister, :show, { :id => "foo" })
}.should raise_error(Merb::ControllerExceptions::NotFound)
end
it "should call display on the node registration" do
Chef::OpenIDRegistration.stub!(:load).and_return(true)
dispatch_to(OpenidRegister, :show, { :id => "foo" }) do |c|
c.should_receive(:display).with(true)
end
end
end
describe OpenidRegister, "create action" do
def do_create
dispatch_to(OpenidRegister, :create, { :id => "foo", :password => "beck" }) do |c|
c.stub!(:display)
end
end
it "should require an id to register" do
lambda {
dispatch_to(OpenidRegister, :create, { :password => "beck" })
}.should raise_error(Merb::ControllerExceptions::BadRequest)
end
it "should require a password to register" do
lambda {
dispatch_to(OpenidRegister, :create, { :id => "foo" })
}.should raise_error(Merb::ControllerExceptions::BadRequest)
end
it "should return 400 if a node is already registered" do
Chef::OpenIDRegistration.should_receive(:has_key?).with("foo").and_return(true)
lambda {
dispatch_to(OpenidRegister, :create, { :id => "foo", :password => "beck" })
}.should raise_error(Merb::ControllerExceptions::BadRequest)
end
it "should store the registration in a new Chef::OpenIDRegistration" do
mock_reg = mock("Chef::OpenIDRegistration", :null_object => true)
mock_reg.should_receive(:name=).with("foo").and_return(true)
mock_reg.should_receive(:set_password).with("beck").and_return(true)
mock_reg.should_receive(:save).and_return(true)
Chef::OpenIDRegistration.stub!(:has_key?).and_return(false)
Chef::OpenIDRegistration.should_receive(:new).and_return(mock_reg)
do_create
end
end
describe OpenidRegister, "update action" do
it "should raise a 400 error" do
lambda {
dispatch_to(OpenidRegister, :update)
}
end
end
describe OpenidRegister, "destroy action" do
def do_destroy
dispatch_to(OpenidRegister, :destroy, { :id => "foo" }) do |c|
c.stub!(:display)
end
end
it "should return 400 if it cannot find the registration" do
Chef::OpenIDRegistration.should_receive(:load).and_raise(ArgumentError)
lambda {
do_destroy
}.should raise_error(Merb::ControllerExceptions::BadRequest)
end
it "should delete the registration from the store" do
mock_reg = mock("OpenIDRegistration")
mock_reg.should_receive(:destroy).and_return(true)
Chef::OpenIDRegistration.should_receive(:load).with("foo").and_return(mock_reg)
do_destroy
end
end
|