foscam-ruby 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foscam::Model::FtpServer do
4
+
5
+ def valid_client_params
6
+ {:url => "http://192.168.0.1/", :username => "foobar", :password => "secret"}
7
+ end
8
+
9
+ def default_get_params
10
+ {
11
+ :ftp_svr => "192.168.0.148",
12
+ :ftp_port => 21,
13
+ :ftp_user => "foobar",
14
+ :ftp_pwd => "secret",
15
+ :ftp_dir => "foscam",
16
+ :ftp_mode => 1,
17
+ :ftp_upload_interval => 0,
18
+ :ftp_filename => "",
19
+ :ftp_numberoffiles => 5,
20
+ :ftp_schedule_enable => false,
21
+ :ftp_schedule => Foscam::Schedule::Week.new
22
+ }
23
+ end
24
+
25
+ before(:each) do
26
+ @client = ::Foscam::Client.new(valid_client_params)
27
+ @client.stub(:get_params).and_return(default_get_params)
28
+ end
29
+
30
+
31
+ describe "#client=" do
32
+ before(:each) do
33
+ @ftp = Foscam::Model::FtpServer.instance
34
+ end
35
+ it "sets the current Foscam::Client" do
36
+ @ftp.client = @client
37
+ @ftp.client.should eql(@client)
38
+ end
39
+
40
+ it "sets the ftp parameters" do
41
+ @ftp.client = @client
42
+ @ftp.dir.should == default_get_params[:ftp_dir]
43
+ @ftp.address.should == default_get_params[:ftp_svr]
44
+ @ftp.port.should == default_get_params[:ftp_port]
45
+ @ftp.username.should == default_get_params[:ftp_user]
46
+ @ftp.password.should == default_get_params[:ftp_pwd]
47
+ @ftp.upload_interval.should == default_get_params[:ftp_upload_interval]
48
+ end
49
+ end
50
+
51
+ describe "#save" do
52
+ before(:each) do
53
+ # @client.stub(:get_params).and_return(one_device_response)
54
+ @ftp = Foscam::Model::FtpServer.instance
55
+ end
56
+ context "with valid params" do
57
+ before(:each) do
58
+ @ftp.stub(:is_valid?).and_return(true)
59
+ end
60
+ context "is dirty" do
61
+ context "request is successful" do
62
+ before(:each) do
63
+ params = {:dir => "path/root/", :user => "foobar1", :pwd => "secret1", :svr => "192.168.0.2", :port => 21,:upload_interval => 0}
64
+ # @ftp.stub(:changed?).and_return(true)
65
+ @client.should_receive(:set_ftp).with(params).once
66
+ @client.stub(:set_ftp).and_return(true)
67
+ end
68
+ it "updates the ftp attributes that changed" do
69
+ @ftp.client = @client
70
+ @ftp.username = "foobar1"
71
+ @ftp.password = "secret1"
72
+ @ftp.dir = "path/root/"
73
+ @ftp.address = "192.168.0.2"
74
+ flag = @ftp.save
75
+ flag.should be_true
76
+ end
77
+ end
78
+ context "request is unsuccessful" do
79
+ before(:each) do
80
+ params = {:dir => "path/root/", :user => "foobar1", :pwd => "secret1", :svr => "192.168.0.2"}
81
+ # @ftp.stub(:changed?).and_return(true)
82
+ @client.should_receive(:set_ftp).with(params).once
83
+ @client.stub(:set_ftp).and_return(false)
84
+ end
85
+ it "fails to update the device attributes" do
86
+ @ftp.client = @client
87
+ @ftp.username = "foobar1"
88
+ @ftp.password = "secret1"
89
+ @ftp.dir = "path/root/"
90
+ @ftp.address = "192.168.0.2"
91
+ flag = @ftp.save
92
+ flag.should be_false
93
+ end
94
+ end
95
+ end
96
+ context "is not dirty" do
97
+ before(:each) do
98
+ @ftp.stub(:changed?).and_return(false)
99
+ end
100
+ it "skips updating since nothing changed" do
101
+ @client.should_not_receive(:set_ftp)
102
+ @ftp.client = @client
103
+ flag = @ftp.save
104
+ flag.should be_false
105
+ end
106
+ end
107
+ end
108
+ context "with invalid params" do
109
+ before(:each) do
110
+ @ftp.stub(:is_valid?).and_return(false)
111
+ end
112
+ it "skips updating since nothing changed" do
113
+ @client.should_not_receive(:set_ftp)
114
+ @ftp.client = @client
115
+ flag = @ftp.save
116
+ flag.should be_false
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "#clear" do
122
+ before(:each) do
123
+ @ftp = Foscam::Model::FtpServer.instance
124
+ end
125
+ it "should save the user with blank usernames, password and privileges" do
126
+ params = {:dir => "", :user => "", :pwd => "", :svr => "", :port => 21, :upload_interval => 0}
127
+ @client.stub(:set_ftp).with(params).and_return(true)
128
+ @client.should_receive(:set_ftp).with(params).once
129
+ @ftp.client = @client
130
+ flag = @ftp.clear
131
+ flag.should be_true
132
+ end
133
+ end
134
+
135
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foscam::Model::MailServer do
4
+
5
+ def valid_client_params
6
+ {:url => "http://192.168.0.1/", :username => "foobar", :password => "secret"}
7
+ end
8
+
9
+ def default_get_params
10
+ {
11
+ :mail_svr => "192.168.0.148",
12
+ :mail_port => 21,
13
+ :mail_user => "foobar",
14
+ :mail_pwd => "secret",
15
+ :mail_sender => "foscam"
16
+ }
17
+ end
18
+
19
+ before(:each) do
20
+ @client = ::Foscam::Client.new(valid_client_params)
21
+ @client.stub(:get_params).and_return(default_get_params)
22
+ end
23
+
24
+ describe "#client=" do
25
+ before(:each) do
26
+ @mail = Foscam::Model::MailServer.instance
27
+ end
28
+ it "sets the current Foscam::Client" do
29
+ @mail.client = @client
30
+ @mail.client.should eql(@client)
31
+ end
32
+
33
+ it "sets the mail parameters" do
34
+ @mail.client = @client
35
+ @mail.sender.should == default_get_params[:mail_sender]
36
+ @mail.address.should == default_get_params[:mail_svr]
37
+ @mail.port.should == default_get_params[:mail_port]
38
+ @mail.username.should == default_get_params[:mail_user]
39
+ @mail.password.should == default_get_params[:mail_pwd]
40
+ end
41
+ end
42
+
43
+ describe "#save" do
44
+ before(:each) do
45
+ # @client.stub(:get_params).and_return(one_device_response)
46
+ @mail = Foscam::Model::MailServer.instance
47
+ end
48
+ context "with valid params" do
49
+ before(:each) do
50
+ @mail.stub(:is_valid?).and_return(true)
51
+ end
52
+ context "is dirty" do
53
+
54
+ context "request is successful" do
55
+ before(:each) do
56
+ params = {:sender => "foo@bar.com", :user => "foobar1", :pwd => "secret1", :svr => "192.168.0.2", :port => 21}
57
+ @client.should_receive(:set_mail).with(params).once
58
+ @client.stub(:set_mail).and_return(true)
59
+ end
60
+ it "updates the mail attributes that changed" do
61
+ @mail.client = @client
62
+ @mail.username = "foobar1"
63
+ @mail.password = "secret1"
64
+ @mail.sender = "foo@bar.com"
65
+ @mail.address = "192.168.0.2"
66
+ flag = @mail.save
67
+ flag.should be_true
68
+ end
69
+ end
70
+ context "request is unsuccessful" do
71
+ before(:each) do
72
+ params = {:sender => "foo@bar.com", :user => "foobar1", :pwd => "secret1", :svr => "192.168.0.2"}
73
+ @client.should_receive(:set_mail).with(params).once
74
+ @client.stub(:set_mail).and_return(false)
75
+ end
76
+ it "fails to update the device attributes" do
77
+ @mail.client = @client
78
+ @mail.username = "foobar1"
79
+ @mail.password = "secret1"
80
+ @mail.sender = "foo@bar.com"
81
+ @mail.address = "192.168.0.2"
82
+ flag = @mail.save
83
+ flag.should be_false
84
+ end
85
+ end
86
+ end
87
+ context "is not dirty" do
88
+ before(:each) do
89
+ @mail.stub(:changed?).and_return(false)
90
+ end
91
+ it "skips updating since nothing changed" do
92
+ @client.should_not_receive(:set_mail)
93
+ @mail.client = @client
94
+ flag = @mail.save
95
+ flag.should be_false
96
+ end
97
+ end
98
+ end
99
+ context "with invalid params" do
100
+ before(:each) do
101
+ @mail.stub(:is_valid?).and_return(false)
102
+ end
103
+ it "skips updating since nothing changed" do
104
+ @client.should_not_receive(:set_mail)
105
+ @mail.client = @client
106
+ flag = @mail.save
107
+ flag.should be_false
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#clear" do
113
+ before(:each) do
114
+ @mail = Foscam::Model::MailServer.instance
115
+ end
116
+ it "should save the user with blank usernames, password and privileges" do
117
+ params = {:sender => "", :user => "", :pwd => "", :svr => "", :port => 21, :receiver1 => "", :receiver2 => "", :receiver3 => "", :receiver4 => ""}
118
+ @client.stub(:set_mail).with(params).and_return(true)
119
+ @client.should_receive(:set_mail).with(params).once
120
+ @mail.client = @client
121
+ flag = @mail.clear
122
+ flag.should be_true
123
+ end
124
+ end
125
+
126
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foscam::Model::Network do
4
+
5
+ def valid_client_params
6
+ {:url => "http://192.168.0.1/", :username => "foobar", :password => "secret"}
7
+ end
8
+
9
+ def default_get_params
10
+ {
11
+ :ip => "192.168.0.148",
12
+ :mask => "8.8.8.8",
13
+ :gateway => "0.0.0.0",
14
+ :dns => "0.0.0.0",
15
+ :port => 80
16
+ }
17
+ end
18
+
19
+ before(:each) do
20
+ @client = ::Foscam::Client.new(valid_client_params)
21
+ @client.stub(:get_params).and_return(default_get_params)
22
+ end
23
+
24
+
25
+ describe "#client=" do
26
+ before(:each) do
27
+ @network = Foscam::Model::Network.instance
28
+ end
29
+ it "sets the current Foscam::Client" do
30
+ @network.client = @client
31
+ @network.client.should eql(@client)
32
+ end
33
+
34
+ it "sets the ftp parameters" do
35
+ @network.client = @client
36
+ @network.ip_address.should == default_get_params[:ip]
37
+ @network.mask.should == default_get_params[:mask]
38
+ @network.gateway.should == default_get_params[:gateway]
39
+ @network.dns.should == default_get_params[:dns]
40
+ @network.port.should == default_get_params[:port]
41
+ end
42
+ end
43
+
44
+ describe "#save" do
45
+ before(:each) do
46
+ # @client.stub(:get_params).and_return(one_device_response)
47
+ @network = Foscam::Model::Network.instance
48
+ end
49
+ context "with valid params" do
50
+ before(:each) do
51
+ @network.stub(:is_valid?).and_return(true)
52
+ end
53
+ context "is dirty" do
54
+ context "request is successful" do
55
+ before(:each) do
56
+ params = {
57
+ :ip => "192.168.1.3",
58
+ :mask => "255.255.255.0",
59
+ :gateway => "192.168.1.1",
60
+ :dns => "192.168.1.1",
61
+ :port => 8080
62
+ }
63
+ # @network.stub(:changed?).and_return(true)
64
+ @client.should_receive(:set_network).with(params).once
65
+ @client.stub(:set_network).and_return(true)
66
+ end
67
+ it "updates the ftp attributes that changed" do
68
+ @network.client = @client
69
+ @network.ip_address = "192.168.1.3"
70
+ @network.mask = "255.255.255.0"
71
+ @network.gateway = "192.168.1.1"
72
+ @network.dns = "192.168.1.1"
73
+ @network.port = 8080
74
+ flag = @network.save
75
+ flag.should be_true
76
+ end
77
+ end
78
+ context "request is unsuccessful" do
79
+ before(:each) do
80
+ params = {
81
+ :ip => "192.168.1.3",
82
+ :mask => "255.255.255.0",
83
+ :gateway => "192.168.1.1",
84
+ :dns => "192.168.1.1",
85
+ :port => 8080
86
+ }
87
+ # @network.stub(:changed?).and_return(true)
88
+ @client.should_receive(:set_network).with(params).once
89
+ @client.stub(:set_network).and_return(false)
90
+ end
91
+ it "fails to update the device attributes" do
92
+ @network.client = @client
93
+ @network.ip_address = "192.168.1.3"
94
+ @network.mask = "255.255.255.0"
95
+ @network.gateway = "192.168.1.1"
96
+ @network.dns = "192.168.1.1"
97
+ @network.port = 8080
98
+ flag = @network.save
99
+ flag.should be_false
100
+ end
101
+ end
102
+ end
103
+ context "is not dirty" do
104
+ before(:each) do
105
+ @network.stub(:changed?).and_return(false)
106
+ end
107
+ it "skips updating since nothing changed" do
108
+ @client.should_not_receive(:set_network)
109
+ @network.client = @client
110
+ flag = @network.save
111
+ flag.should be_false
112
+ end
113
+ end
114
+ end
115
+ context "with invalid params" do
116
+ before(:each) do
117
+ @network.stub(:is_valid?).and_return(false)
118
+ end
119
+ it "skips updating since nothing changed" do
120
+ @client.should_not_receive(:set_network)
121
+ @network.client = @client
122
+ flag = @network.save
123
+ flag.should be_false
124
+ end
125
+ end
126
+ end
127
+
128
+ end
@@ -0,0 +1,322 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foscam::Model::User do
4
+
5
+ def all_users_response
6
+ {
7
+ :user1_name => "user_1", :user1_pwd => "pass_1", :user1_pri => :administrator,
8
+ :user2_name => "user_2", :user2_pwd => "pass_2", :user2_pri => :administrator,
9
+ :user3_name => "user_3", :user3_pwd => "pass_3", :user3_pri => :administrator,
10
+ :user4_name => "user_4", :user4_pwd => "pass_4", :user4_pri => :administrator,
11
+ :user5_name => "user_5", :user5_pwd => "pass_5", :user5_pri => :administrator,
12
+ :user6_name => "user_6", :user6_pwd => "pass_6", :user6_pri => :administrator,
13
+ :user7_name => "user_7", :user7_pwd => "pass_7", :user7_pri => :administrator,
14
+ :user8_name => "user_8", :user8_pwd => "pass_8", :user8_pri => :administrator,
15
+ }
16
+ end
17
+
18
+ def one_user_response
19
+ {
20
+ :user1_name => "user_1", :user1_pwd => "pass_1", :user1_pri => :administrator,
21
+ :user2_name => "", :user2_pwd => "", :user2_pri => :visitor,
22
+ :user3_name => "", :user3_pwd => "", :user3_pri => :visitor,
23
+ :user4_name => "", :user4_pwd => "", :user4_pri => :visitor,
24
+ :user5_name => "", :user5_pwd => "", :user5_pri => :visitor,
25
+ :user6_name => "", :user6_pwd => "", :user6_pri => :visitor,
26
+ :user7_name => "", :user7_pwd => "", :user7_pri => :visitor,
27
+ :user8_name => "", :user8_pwd => "", :user8_pri => :visitor,
28
+ }
29
+ end
30
+
31
+ def valid_params
32
+ {:username => 'foobar', :password => 'secret', :privilege => :administrator}
33
+ end
34
+ before(:all) do
35
+ @client = ::Foscam::Client.new({:url => "http://192.168.0.1/", :username => "foobar", :password => "secret"})
36
+ end
37
+ describe ".all" do
38
+ it "returns an array of all the users" do
39
+ @client.stub(:get_params).and_return(all_users_response)
40
+ @client.should_receive(:get_params).once
41
+ Foscam::Model::User.client = @client
42
+ users = Foscam::Model::User.all
43
+ users.count.should == 8
44
+ index = 1
45
+ users.each do |user|
46
+ user.should be_an_instance_of(Foscam::Model::User)
47
+ user.id.should == index
48
+ user.username.should == "user_#{index}"
49
+ user.password.should == "pass_#{index}"
50
+ user.privilege.should == :administrator
51
+ index += 1
52
+ end
53
+ end
54
+ end
55
+
56
+ describe ".create" do
57
+ it "builds a user and then saves it" do
58
+ Foscam::Model::User.any_instance.stub(:save).and_return(true)
59
+ Foscam::Model::User.any_instance.should_receive(:save).once
60
+ user = Foscam::Model::User.create(valid_params)
61
+ user.should_not be_nil
62
+ user.username.should == valid_params[:username]
63
+ user.password.should == valid_params[:password]
64
+ user.privilege.should == valid_params[:privilege]
65
+ end
66
+ end
67
+
68
+ describe ".find" do
69
+ before(:each) do
70
+ @client.stub(:get_params).and_return(one_user_response)
71
+ end
72
+ context "when user exists" do
73
+ context "with valid id" do
74
+ it "returns the desired user by id" do
75
+ @client.should_receive(:get_params).once
76
+ Foscam::Model::User.client = @client
77
+ user = Foscam::Model::User.find(1)
78
+ user.should be_an_instance_of(Foscam::Model::User)
79
+ user.id.should == 1
80
+ user.username.should == "user_1"
81
+ user.password.should == "pass_1"
82
+ user.privilege.should == :administrator
83
+ end
84
+ end
85
+ end
86
+
87
+ context "when user doesn't exists" do
88
+ context "with valid id" do
89
+ it "returns a nil object" do
90
+ @client.should_receive(:get_params).once
91
+ Foscam::Model::User.client = @client
92
+ user = Foscam::Model::User.find(2)
93
+ user.should be_nil
94
+ end
95
+ end
96
+ context "with invalid id" do
97
+ it "returns a nil object" do
98
+ @client.should_not_receive(:get_params)
99
+ Foscam::Model::User.client = @client
100
+ user = Foscam::Model::User.find(10)
101
+ user.should be_nil
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ describe ".delete" do
108
+ context "with valid id" do
109
+ it "deletes the desired user" do
110
+ params = {:user1 => "", :pwd1 => "", :pri1 => 0}
111
+ @client.stub(:set_users).with(params).and_return(true)
112
+ @client.should_receive(:set_users).with(params).once
113
+ Foscam::Model::User.client = @client
114
+ flag = Foscam::Model::User.delete(1)
115
+ flag.should be_true
116
+ end
117
+ end
118
+ context "with invalid id" do
119
+ it "deletes the desired user" do
120
+ @client.should_not_receive(:set_users)
121
+ Foscam::Model::User.client = @client
122
+ flag = Foscam::Model::User.delete(10)
123
+ flag.should be_false
124
+ end
125
+ end
126
+ end
127
+
128
+ describe "#save" do
129
+ context "a new user" do
130
+ before(:each) do
131
+ @user = Foscam::Model::User.new(valid_params)
132
+ end
133
+
134
+ context "with valid params" do
135
+ before(:each) do
136
+ @user.stub(:is_valid?).and_return(true)
137
+ end
138
+
139
+ context "with less than the maximum number of users" do
140
+ before(:each) do
141
+ @client.stub(:get_params).and_return(one_user_response)
142
+ params = {:user2 => @user.username, :pwd2 => @user.password, :pri2 => :administrator}
143
+ @client.should_receive(:set_users).with(params).once
144
+ end
145
+ context "request is successful" do
146
+ before(:each) do
147
+ @client.stub(:set_users).and_return(true)
148
+ end
149
+ it "updates the user attributes that changed" do
150
+ Foscam::Model::User.client = @client
151
+ flag = @user.save
152
+ flag.should be_true
153
+ end
154
+ end
155
+ context "request is unsuccessful" do
156
+ before(:each) do
157
+ @client.stub(:set_users).and_return(false)
158
+ end
159
+ it "fails to update the user attributes" do
160
+ Foscam::Model::User.client = @client
161
+ flag = @user.save
162
+ flag.should be_false
163
+ end
164
+ end
165
+ end
166
+ context "with the maximum number of users" do
167
+ before(:each) do
168
+ @client.stub(:get_params).and_return(all_users_response)
169
+ end
170
+ it "skips creation since no spots are available for new users" do
171
+ @client.should_not_receive(:set_users)
172
+ Foscam::Model::User.client = @client
173
+ flag = @user.save
174
+ flag.should be_false
175
+ end
176
+ end
177
+ end
178
+ context "with invalid params" do
179
+ before(:each) do
180
+ @user.stub(:is_valid?).and_return(false)
181
+ end
182
+ it "skips updating since nothing changed" do
183
+ @client.should_not_receive(:set_users)
184
+ Foscam::Model::User.client = @client
185
+ flag = @user.save
186
+ flag.should be_false
187
+ end
188
+ end
189
+ end
190
+
191
+ context "an existing user" do
192
+ before(:each) do
193
+ @client.stub(:get_params).and_return(one_user_response)
194
+ @user = Foscam::Model::User.find(1)
195
+ end
196
+ context "with valid params" do
197
+ before(:each) do
198
+ @user.username = "foobar"
199
+ @user.password = "secret"
200
+ @user.stub(:is_valid?).and_return(true)
201
+ end
202
+ context "is dirty" do
203
+ before(:each) do
204
+ @user.stub(:changed?).and_return(true)
205
+ params = {:user1 => @user.username, :pwd1 => @user.password, :pri1 => :administrator}
206
+ @client.should_receive(:set_users).with(params).once
207
+ end
208
+ context "request is successful" do
209
+ before(:each) do
210
+ @client.stub(:set_users).and_return(true)
211
+ end
212
+ it "updates the user attributes that changed" do
213
+ Foscam::Model::User.client = @client
214
+ flag = @user.save
215
+ flag.should be_true
216
+ end
217
+ end
218
+ context "request is unsuccessful" do
219
+ before(:each) do
220
+ @client.stub(:set_users).and_return(false)
221
+ end
222
+ it "fails to update the user attributes" do
223
+ Foscam::Model::User.client = @client
224
+ flag = @user.save
225
+ flag.should be_false
226
+ end
227
+ end
228
+ end
229
+ context "is not dirty" do
230
+ before(:each) do
231
+ @user.stub(:changed?).and_return(false)
232
+ end
233
+ it "skips updating since nothing changed" do
234
+ @client.should_not_receive(:set_users)
235
+ Foscam::Model::User.client = @client
236
+ flag = @user.save
237
+ flag.should be_false
238
+ end
239
+ end
240
+ end
241
+ context "with invalid params" do
242
+ before(:each) do
243
+ @user.stub(:is_valid?).and_return(false)
244
+ end
245
+ it "skips updating since nothing changed" do
246
+ @client.should_not_receive(:set_users)
247
+ Foscam::Model::User.client = @client
248
+ flag = @user.save
249
+ flag.should be_false
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ describe "#==" do
256
+ before(:each) do
257
+ @user = Foscam::Model::User.new(valid_params)
258
+ end
259
+ it "returns true if the other is the same object" do
260
+ flag = @user == @user
261
+ flag.should be_true
262
+ end
263
+
264
+ it "returns false if it is not an instance of Foscam::Model::User" do
265
+ flag = @user == valid_params
266
+ flag.should be_false
267
+ end
268
+
269
+ it "returns false if it is an instance of Foscam::Model::User but the ids are different" do
270
+ user2 = Foscam::Model::User.new(valid_params)
271
+ @user.instance_variable_set(:@id, 1)
272
+ user2.instance_variable_set(:@id, 2)
273
+ flag = @user == user2
274
+ flag.should be_false
275
+ end
276
+
277
+ it "returns false if either or both ids is not set" do
278
+ user2 = Foscam::Model::User.new({:username => "user_1", :password => "pass_1", :privilege => :administrator})
279
+ flag = @user == user2
280
+ flag.should be_false
281
+ @user.instance_variable_set(:@id, 1)
282
+ flag = @user == user2
283
+ flag.should be_false
284
+ @user.instance_variable_set(:@id, nil)
285
+ user2.instance_variable_set(:@id, 1)
286
+ flag = @user == user2
287
+ flag.should be_false
288
+ end
289
+ end
290
+
291
+ describe "#destroy" do
292
+ context "on a new user" do
293
+ before(:each) do
294
+ @user = Foscam::Model::User.new(valid_params)
295
+ end
296
+ it "should set the user attributes to be blank" do
297
+ @client.should_not_receive(:set_users)
298
+ Foscam::Model::User.client = @client
299
+ flag = @user.destroy
300
+ flag.should be_false
301
+ @user.username.should == ""
302
+ @user.password.should == ""
303
+ @user.privilege.should == 0
304
+ end
305
+ end
306
+ context "an existing user" do
307
+ before(:each) do
308
+ @client.stub(:get_params).and_return(one_user_response)
309
+ @user = Foscam::Model::User.find(1)
310
+ end
311
+ it "should save the user with blank usernames, password and privileges" do
312
+ params = {:user1 => "", :pwd1 => "", :pri1 => 0}
313
+ @client.stub(:set_users).with(params).and_return(true)
314
+ @client.should_receive(:set_users).with(params).once
315
+ Foscam::Model::User.client = @client
316
+ flag = @user.destroy
317
+ flag.should be_true
318
+ end
319
+ end
320
+ end
321
+
322
+ end