osm 0.1.17 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ describe "Grouping" do
5
5
 
6
6
  describe "Using the API" do
7
7
 
8
- it "Create" do
8
+ it "Get for section" do
9
9
  body = {'patrols' => [{
10
10
  'patrolid' => 1,
11
11
  'name' => 'Patrol Name',
@@ -31,6 +31,64 @@ describe "Grouping" do
31
31
  patrols.size.should == 0
32
32
  end
33
33
 
34
+
35
+ it "Update in OSM (succeded)" do
36
+ grouping = Osm::Grouping.new(
37
+ :id => 1,
38
+ :section_id => 2,
39
+ :active => true,
40
+ :points => 3
41
+ )
42
+ grouping.name = 'Grouping'
43
+
44
+ url = "https://www.onlinescoutmanager.co.uk/users.php?action=editPatrol&sectionid=#{grouping.section_id}"
45
+ HTTParty.should_receive(:post).with(url, {:body => {
46
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
47
+ 'token' => @CONFIGURATION[:api][:osm][:token],
48
+ 'userid' => 'user_id',
49
+ 'secret' => 'secret',
50
+ 'patrolid' => grouping.id,
51
+ 'name' => grouping.name,
52
+ 'active' => grouping.active,
53
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>''}) }
54
+
55
+ grouping.update(@api).should be_true
56
+ end
57
+
58
+ it "Update points in OSM (succeded)" do
59
+ grouping = Osm::Grouping.new(
60
+ :id => 1,
61
+ :section_id => 2,
62
+ :active => true,
63
+ :name => 'Grouping'
64
+ )
65
+ grouping.points = 3
66
+
67
+ url = "https://www.onlinescoutmanager.co.uk/users.php?action=updatePatrolPoints&sectionid=#{grouping.section_id}"
68
+ HTTParty.should_receive(:post).with(url, {:body => {
69
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
70
+ 'token' => @CONFIGURATION[:api][:osm][:token],
71
+ 'userid' => 'user_id',
72
+ 'secret' => 'secret',
73
+ 'patrolid' => grouping.id,
74
+ 'points' => grouping.points,
75
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
76
+
77
+ grouping.update(@api).should be_true
78
+ end
79
+ it "Update in OSM (failed)" do
80
+ grouping = Osm::Grouping.new(
81
+ :id => 1,
82
+ :section_id => 2,
83
+ )
84
+ grouping.name = 'Grouping'
85
+ grouping.points = 3
86
+ grouping.active = true
87
+
88
+ HTTParty.stub(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"done":false}'}) }
89
+ grouping.update(@api).should be_false
90
+ end
91
+
34
92
  end
35
93
 
36
94
  end
@@ -2,13 +2,13 @@
2
2
  require 'spec_helper'
3
3
  require 'date'
4
4
 
5
- describe "Evening" do
5
+ describe "Meeting" do
6
6
 
7
7
  it "Create" do
8
- e = Osm::Evening.new(
8
+ e = Osm::Meeting.new(
9
9
  :id => 1,
10
10
  :section_id => 2,
11
- :title => 'Evening Name',
11
+ :title => 'Meeting Name',
12
12
  :notes_for_parents => 'Notes for parents',
13
13
  :games => 'Games',
14
14
  :pre_notes => 'Before',
@@ -16,13 +16,13 @@ describe "Evening" do
16
16
  :leaders => 'Leaders',
17
17
  :start_time => '19:00',
18
18
  :finish_time => '21:00',
19
- :meeting_date => Date.new(2000, 01, 02),
19
+ :date => Date.new(2000, 01, 02),
20
20
  :activities => []
21
21
  )
22
22
 
23
23
  e.id.should == 1
24
24
  e.section_id.should == 2
25
- e.title.should == 'Evening Name'
25
+ e.title.should == 'Meeting Name'
26
26
  e.notes_for_parents.should == 'Notes for parents'
27
27
  e.games.should == 'Games'
28
28
  e.pre_notes.should == 'Before'
@@ -30,25 +30,25 @@ describe "Evening" do
30
30
  e.leaders.should == 'Leaders'
31
31
  e.start_time.should == '19:00'
32
32
  e.finish_time.should == '21:00'
33
- e.meeting_date.should == Date.new(2000, 1, 2)
33
+ e.date.should == Date.new(2000, 1, 2)
34
34
  e.activities.should == []
35
35
  e.valid?.should be_true
36
36
  end
37
37
 
38
- it "Sorts by Section ID, Meeting date, Start time and then Evening ID" do
39
- evening1 = Osm::Evening.new(:section_id => 1, :id => 1, :meeting_date => (Date.today - 1), :start_time => '18:00')
40
- evening2 = Osm::Evening.new(:section_id => 2, :id => 1, :meeting_date => (Date.today - 1), :start_time => '18:00')
41
- evening3 = Osm::Evening.new(:section_id => 2, :id => 1, :meeting_date => (Date.today + 1), :start_time => '18:00')
42
- evening4 = Osm::Evening.new(:section_id => 2, :id => 1, :meeting_date => (Date.today + 1), :start_time => '19:00')
43
- evening5 = Osm::Evening.new(:section_id => 2, :id => 2, :meeting_date => (Date.today + 1), :start_time => '19:00')
38
+ it "Sorts by Section ID, Meeting date, Start time and then Meeting ID" do
39
+ meeting1 = Osm::Meeting.new(:section_id => 1, :id => 1, :date => (Date.today - 1), :start_time => '18:00')
40
+ meeting2 = Osm::Meeting.new(:section_id => 2, :id => 1, :date => (Date.today - 1), :start_time => '18:00')
41
+ meeting3 = Osm::Meeting.new(:section_id => 2, :id => 1, :date => (Date.today + 1), :start_time => '18:00')
42
+ meeting4 = Osm::Meeting.new(:section_id => 2, :id => 1, :date => (Date.today + 1), :start_time => '19:00')
43
+ meeting5 = Osm::Meeting.new(:section_id => 2, :id => 2, :date => (Date.today + 1), :start_time => '19:00')
44
44
 
45
- data = [evening5, evening3, evening2, evening4, evening1]
46
- data.sort.should == [evening1, evening2, evening3, evening4, evening5]
45
+ data = [meeting5, meeting3, meeting2, meeting4, meeting1]
46
+ data.sort.should == [meeting1, meeting2, meeting3, meeting4, meeting5]
47
47
  end
48
48
 
49
49
 
50
- it "Create Evening::Activity" do
51
- ea = Osm::Evening::Activity.new(
50
+ it "Create Meeting::Activity" do
51
+ ea = Osm::Meeting::Activity.new(
52
52
  :activity_id => 2,
53
53
  :title => 'Activity Name',
54
54
  :notes => 'Notes',
@@ -72,13 +72,13 @@ describe "Evening" do
72
72
  body = {"items" => items, "activities" => activities}
73
73
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/programme.php?action=getProgramme&sectionid=3&termid=4", :body => body.to_json)
74
74
 
75
- programme = Osm::Evening.get_programme(@api, 3, 4)
75
+ programme = Osm::Meeting.get_for_section(@api, 3, 4)
76
76
  programme.size.should == 1
77
- programme[0].is_a?(Osm::Evening).should be_true
77
+ programme[0].is_a?(Osm::Meeting).should be_true
78
78
  programme[0].activities.size.should == 2
79
79
  end
80
80
 
81
- it "Fetch badge requirements for an evening" do
81
+ it "Fetch badge requirements for a meeting" do
82
82
  badges_body = [{'a'=>'a'},{'a'=>'A'}]
83
83
  FakeWeb.register_uri(:post, 'https://www.onlinescoutmanager.co.uk/users.php?action=getActivityRequirements&date=2000-01-02&sectionid=3&section=cubs', :body => badges_body.to_json)
84
84
  roles_body = [
@@ -86,11 +86,11 @@ describe "Evening" do
86
86
  ]
87
87
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => roles_body.to_json)
88
88
 
89
- evening = Osm::Evening.new(:meeting_date => Date.new(2000, 1, 2), :section_id => 3)
90
- evening.get_badge_requirements(@api).should == badges_body
89
+ meeting = Osm::Meeting.new(:date => Date.new(2000, 1, 2), :section_id => 3)
90
+ meeting.get_badge_requirements(@api).should == badges_body
91
91
  end
92
92
 
93
- it "Create an evening (succeded)" do
93
+ it "Create a meeting (succeded)" do
94
94
  url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
95
95
  post_data = {
96
96
  'apiid' => @CONFIGURATION[:api][:osm][:id],
@@ -107,22 +107,22 @@ describe "Evening" do
107
107
  }
108
108
 
109
109
  Osm::Term.stub(:get_for_section) { [] }
110
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
111
- Osm::Evening.create(@api, {
110
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
111
+ Osm::Meeting.create(@api, {
112
112
  :section_id => 1,
113
- :meeting_date => Date.new(2000, 1, 2),
113
+ :date => Date.new(2000, 1, 2),
114
114
  :start_time => '11:11',
115
115
  :finish_time => '22:22',
116
116
  :title => 'Title',
117
117
  }).should be_true
118
118
  end
119
119
 
120
- it "Create an evening (failed)" do
120
+ it "Create a meeting (failed)" do
121
121
  Osm::Term.stub(:get_for_section) { [] }
122
- HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'[]'}) }
123
- Osm::Evening.create(@api, {
122
+ HTTParty.should_receive(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'[]'}) }
123
+ Osm::Meeting.create(@api, {
124
124
  :section_id => 1,
125
- :meeting_date => Date.new(2000, 1, 2),
125
+ :date => Date.new(2000, 1, 2),
126
126
  :start_time => '11:11',
127
127
  :finish_time => '22:22',
128
128
  :title => 'Title',
@@ -130,7 +130,7 @@ describe "Evening" do
130
130
  end
131
131
 
132
132
 
133
- it "Add activity to evening (succeded)" do
133
+ it "Add activity to meeting (succeded)" do
134
134
  url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
135
135
  post_data = {
136
136
  'apiid' => @CONFIGURATION[:api][:osm][:id],
@@ -144,22 +144,22 @@ describe "Evening" do
144
144
  }
145
145
 
146
146
  Osm::Term.stub(:get_for_section) { [] }
147
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
147
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
148
148
  activity = Osm::Activity.new(:id => 2, :title => 'Title')
149
- evening = Osm::Evening.new(:section_id => 1, :meeting_date => Date.new(2000, 1, 2))
150
- evening.add_activity(@api, activity, 'Notes').should be_true
151
- evening.activities[0].activity_id.should == 2
149
+ meeting = Osm::Meeting.new(:section_id => 1, :date => Date.new(2000, 1, 2))
150
+ meeting.add_activity(@api, activity, 'Notes').should be_true
151
+ meeting.activities[0].activity_id.should == 2
152
152
  end
153
153
 
154
- it "Add activity to evening (failed)" do
155
- HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
154
+ it "Add activity to meeting (failed)" do
155
+ HTTParty.should_receive(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
156
156
  activity = Osm::Activity.new(:id => 2, :title => 'Title')
157
- evening = Osm::Evening.new(:section_id => 1, :meeting_date => Date.new(2000, 1, 2))
158
- evening.add_activity(@api, activity, 'Notes').should be_false
157
+ meeting = Osm::Meeting.new(:section_id => 1, :date => Date.new(2000, 1, 2))
158
+ meeting.add_activity(@api, activity, 'Notes').should be_false
159
159
  end
160
160
 
161
161
 
162
- it "Update an evening (succeded)" do
162
+ it "Update a meeting (succeded)" do
163
163
  url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=editEvening'
164
164
  post_data = {
165
165
  'apiid' => @CONFIGURATION[:api][:osm][:id],
@@ -171,13 +171,13 @@ describe "Evening" do
171
171
  'postnotes' => '', 'games' => '', 'leaders' => '', 'activity' => '[]',
172
172
  }
173
173
  Osm::Term.stub(:get_for_section) { [] }
174
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
174
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
175
175
 
176
- evening = Osm::Evening.new(:id=>1, :section_id=>2, :meeting_date=>Date.new(2000, 01, 02))
177
- evening.update(@api).should be_true
176
+ meeting = Osm::Meeting.new(:id=>1, :section_id=>2, :date=>Date.new(2000, 01, 02))
177
+ meeting.update(@api).should be_true
178
178
  end
179
179
 
180
- it "Update an evening (failed)" do
180
+ it "Update a meeting (failed)" do
181
181
  url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=editEvening'
182
182
  post_data = {
183
183
  'apiid' => @CONFIGURATION[:api][:osm][:id],
@@ -189,19 +189,19 @@ describe "Evening" do
189
189
  'postnotes' => '', 'games' => '', 'leaders' => '', 'activity' => '[]',
190
190
  }
191
191
  Osm::Term.stub(:get_for_section) { [] }
192
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
192
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
193
193
 
194
- evening = Osm::Evening.new(:id=>1, :section_id=>2, :meeting_date=>Date.new(2000, 01, 02))
195
- evening.update(@api).should be_false
194
+ meeting = Osm::Meeting.new(:id=>1, :section_id=>2, :date=>Date.new(2000, 01, 02))
195
+ meeting.update(@api).should be_false
196
196
  end
197
197
 
198
- it "Update an evening (invalid evening)" do
199
- evening = Osm::Evening.new
200
- expect{ evening.update(@api) }.to raise_error(Osm::ObjectIsInvalid)
198
+ it "Update a meeting (invalid meeting)" do
199
+ meeting = Osm::Meeting.new
200
+ expect{ meeting.update(@api) }.to raise_error(Osm::ObjectIsInvalid)
201
201
  end
202
202
 
203
203
 
204
- it "Delete an evening" do
204
+ it "Delete a meeting" do
205
205
  url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=deleteEvening&eveningid=1&sectionid=2'
206
206
  post_data = {
207
207
  'apiid' => @CONFIGURATION[:api][:osm][:id],
@@ -210,10 +210,10 @@ describe "Evening" do
210
210
  'secret' => 'secret',
211
211
  }
212
212
  Osm::Term.stub(:get_for_section) { [] }
213
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>''}) }
213
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>''}) }
214
214
 
215
- evening = Osm::Evening.new(:id=>1, :section_id=>2)
216
- evening.delete(@api).should be_true
215
+ meeting = Osm::Meeting.new(:id=>1, :section_id=>2)
216
+ meeting.delete(@api).should be_true
217
217
  end
218
218
 
219
219
  end
@@ -41,7 +41,6 @@ describe "Member" do
41
41
  :custom9 => 'Custom Field 9',
42
42
  :grouping_id => '3',
43
43
  :grouping_leader => 0,
44
- :grouping_label => 'Grouping',
45
44
  :joined => '2006-01-07',
46
45
  :age => '06/07',
47
46
  :joined_years => 1,
@@ -83,7 +82,6 @@ describe "Member" do
83
82
  member.custom8.should == 'Custom Field 8'
84
83
  member.custom9.should == 'Custom Field 9'
85
84
  member.grouping_id.should == 3
86
- member.grouping_label.should == 'Grouping'
87
85
  member.grouping_leader.should == 0
88
86
  member.joined.should == Date.new(2006, 1, 7)
89
87
  member.age.should == '06/07'
@@ -274,7 +272,7 @@ describe "Member" do
274
272
  }
275
273
 
276
274
  Osm::Term.stub(:get_for_section) { [] }
277
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":"ok","scoutid":1}'}) }
275
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":"ok","scoutid":1}'}) }
278
276
  member.create(@api).should be_true
279
277
  member.id.should == 1
280
278
  end
@@ -291,49 +289,48 @@ describe "Member" do
291
289
  :grouping_leader => 0,
292
290
  )
293
291
 
294
- HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":"ok","scoutid":-1}'}) }
292
+ HTTParty.should_receive(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":"ok","scoutid":-1}'}) }
295
293
  member.create(@api).should be_false
296
294
  end
297
295
 
298
296
 
299
297
  it "Update in OSM (succeded)" do
300
- member = Osm::Member.new(
301
- :id => 1,
302
- :section_id => 2,
303
- :first_name => 'First',
304
- :last_name => 'Last',
305
- :email1 => 'email1@example.com',
306
- :email2 => 'email2@example.com',
307
- :email3 => 'email3@example.com',
308
- :email4 => 'email4@example.com',
309
- :phone1 => '11111 111111',
310
- :phone2 => '222222',
311
- :phone3 => '+33 3333 333333',
312
- :phone4 => '4444 444 444',
313
- :address => '1 Some Road',
314
- :address2 => 'Address 2',
315
- :date_of_birth => '2000-01-02',
316
- :started => '2006-01-02',
317
- :joined => '2006-01-03',
318
- :parents => 'John and Jane Doe',
319
- :notes => 'None',
320
- :medical => 'Nothing',
321
- :religion => 'Unknown',
322
- :school => 'Some School',
323
- :ethnicity => 'Yes',
324
- :subs => 'Upto end of 2007',
325
- :custom1 => 'Custom Field 1',
326
- :custom2 => 'Custom Field 2',
327
- :custom3 => 'Custom Field 3',
328
- :custom4 => 'Custom Field 4',
329
- :custom5 => 'Custom Field 5',
330
- :custom6 => 'Custom Field 6',
331
- :custom7 => 'Custom Field 7',
332
- :custom8 => 'Custom Field 8',
333
- :custom9 => 'Custom Field 9',
334
- :grouping_id => 3,
335
- :grouping_leader => 0,
336
- )
298
+ member = Osm::Member.new()
299
+ member.id = 1
300
+ member.section_id = 2
301
+ member.first_name = 'First'
302
+ member.last_name = 'Last'
303
+ member.email1 = 'email1@example.com'
304
+ member.email2 = 'email2@example.com'
305
+ member.email3 = 'email3@example.com'
306
+ member.email4 = 'email4@example.com'
307
+ member.phone1 = '11111 111111'
308
+ member.phone2 = '222222'
309
+ member.phone3 = '+33 3333 333333'
310
+ member.phone4 = '4444 444 444'
311
+ member.address = '1 Some Road'
312
+ member.address2 = 'Address 2'
313
+ member.date_of_birth = '2000-01-02'
314
+ member.started = '2006-01-02'
315
+ member.joined = '2006-01-03'
316
+ member.parents = 'John and Jane Doe'
317
+ member.notes = 'None'
318
+ member.medical = 'Nothing'
319
+ member.religion = 'Unknown'
320
+ member.school = 'Some School'
321
+ member.ethnicity = 'Yes'
322
+ member.subs = 'Upto end of 2007'
323
+ member.custom1 = 'Custom Field 1'
324
+ member.custom2 = 'Custom Field 2'
325
+ member.custom3 = 'Custom Field 3'
326
+ member.custom4 = 'Custom Field 4'
327
+ member.custom5 = 'Custom Field 5'
328
+ member.custom6 = 'Custom Field 6'
329
+ member.custom7 = 'Custom Field 7'
330
+ member.custom8 = 'Custom Field 8'
331
+ member.custom9 = 'Custom Field 9'
332
+ member.grouping_id = 3
333
+ member.grouping_leader = 0
337
334
 
338
335
  url = 'https://www.onlinescoutmanager.co.uk/users.php?action=updateMember&dateFormat=generic'
339
336
  body_data = {
@@ -384,7 +381,7 @@ describe "Member" do
384
381
  'column' => column,
385
382
  'value' => value,
386
383
  'sectionid' => member.section_id,
387
- }}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>body}) }
384
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body}) }
388
385
  end
389
386
  end
390
387
  HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/users.php?action=updateMemberPatrol', {:body => {
@@ -396,7 +393,59 @@ describe "Member" do
396
393
  'patrolid' => member.grouping_id,
397
394
  'pl' => member.grouping_leader,
398
395
  'sectionid' => member.section_id,
399
- }}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>body}) }
396
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body}) }
397
+ Osm::Term.stub(:get_for_section) { [] }
398
+
399
+ member.update(@api).should be_true
400
+ end
401
+
402
+ it "Update in OSM (only updated fields)" do
403
+ member = Osm::Member.new(
404
+ :id => 1,
405
+ :section_id => 2,
406
+ :date_of_birth => '2000-01-02',
407
+ :started => '2006-01-02',
408
+ :joined => '2006-01-03',
409
+ :grouping_leader => 0,
410
+ )
411
+ member.first_name = 'First'
412
+ member.last_name = 'Last'
413
+ member.grouping_id = 3
414
+
415
+ url = 'https://www.onlinescoutmanager.co.uk/users.php?action=updateMember&dateFormat=generic'
416
+ body_data = {
417
+ 'firstname' => 'First',
418
+ 'lastname' => 'Last',
419
+ 'patrolid' => 3,
420
+ 'patrolleader' => 0,
421
+ }
422
+ body = (body_data.inject({}) {|h,(k,v)| h[k]=v.to_s; h}).to_json
423
+
424
+ body_data.each do |column, value|
425
+ unless ['patrolid', 'patrolleader'].include?(column)
426
+ HTTParty.should_receive(:post).with(url, {:body => {
427
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
428
+ 'token' => @CONFIGURATION[:api][:osm][:token],
429
+ 'userid' => 'user_id',
430
+ 'secret' => 'secret',
431
+ 'scoutid' => member.id,
432
+ 'column' => column,
433
+ 'value' => value,
434
+ 'sectionid' => member.section_id,
435
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body}) }
436
+ end
437
+ end
438
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/users.php?action=updateMemberPatrol', {:body => {
439
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
440
+ 'token' => @CONFIGURATION[:api][:osm][:token],
441
+ 'userid' => 'user_id',
442
+ 'secret' => 'secret',
443
+ 'scoutid' => member.id,
444
+ 'patrolid' => member.grouping_id,
445
+ 'pl' => member.grouping_leader,
446
+ 'sectionid' => member.section_id,
447
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body}) }
448
+ Osm::Term.stub(:get_for_section) { [] }
400
449
 
401
450
  member.update(@api).should be_true
402
451
  end
@@ -405,7 +454,6 @@ describe "Member" do
405
454
  member = Osm::Member.new(
406
455
  :id => 1,
407
456
  :section_id => 2,
408
- :first_name => 'First',
409
457
  :last_name => 'Last',
410
458
  :date_of_birth => '2000-01-02',
411
459
  :started => '2006-01-02',
@@ -413,11 +461,69 @@ describe "Member" do
413
461
  :grouping_id => '3',
414
462
  :grouping_leader => 0,
415
463
  )
464
+ member.first_name = 'First'
416
465
 
417
- HTTParty.stub(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
466
+ HTTParty.stub(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
418
467
  member.update(@api).should be_false
419
468
  end
420
469
 
470
+ describe "Get My.SCOUT link" do
471
+
472
+ before :each do
473
+ @member = Osm::Member.new(
474
+ :id => 1,
475
+ :section_id => 2,
476
+ :first_name => 'First',
477
+ :last_name => 'Last',
478
+ :date_of_birth => '2000-01-02',
479
+ :started => '2006-01-02',
480
+ :joined => '2006-01-03',
481
+ :grouping_id => '3',
482
+ :grouping_leader => 0,
483
+ )
484
+ end
485
+
486
+ it "Default" do
487
+ url = 'https://www.onlinescoutmanager.co.uk/api.php?action=getMyScoutKey&sectionid=2&scoutid=1'
488
+ HTTParty.should_receive(:post).with(url, {:body => {
489
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
490
+ 'token' => @CONFIGURATION[:api][:osm][:token],
491
+ 'userid' => 'user_id',
492
+ 'secret' => 'secret',
493
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"ok":true,"key":"KEY-HERE"}'}) }
494
+ @member.myscout_link(@api).should == 'https://www.onlinescoutmanager.co.uk/parents/badges.php?sc=1&se=2&c=KEY-HERE'
495
+ end
496
+
497
+ it "Payments" do
498
+ url = 'https://www.onlinescoutmanager.co.uk/api.php?action=getMyScoutKey&sectionid=2&scoutid=1'
499
+ FakeWeb.register_uri(:post, url, :body => '{"ok":true,"key":"KEY-HERE"}')
500
+ @member.myscout_link(@api, :payments).should == 'https://www.onlinescoutmanager.co.uk/parents/payments.php?sc=1&se=2&c=KEY-HERE'
501
+ end
502
+
503
+ it "Events" do
504
+ url = 'https://www.onlinescoutmanager.co.uk/api.php?action=getMyScoutKey&sectionid=2&scoutid=1'
505
+ FakeWeb.register_uri(:post, url, :body => '{"ok":true,"key":"KEY-HERE"}')
506
+ @member.myscout_link(@api, :events).should == 'https://www.onlinescoutmanager.co.uk/parents/events.php?sc=1&se=2&c=KEY-HERE'
507
+ end
508
+
509
+ it "Programme" do
510
+ url = 'https://www.onlinescoutmanager.co.uk/api.php?action=getMyScoutKey&sectionid=2&scoutid=1'
511
+ FakeWeb.register_uri(:post, url, :body => '{"ok":true,"key":"KEY-HERE"}')
512
+ @member.myscout_link(@api, :programme).should == 'https://www.onlinescoutmanager.co.uk/parents/programme.php?sc=1&se=2&c=KEY-HERE'
513
+ end
514
+
515
+ it "Badges" do
516
+ url = 'https://www.onlinescoutmanager.co.uk/api.php?action=getMyScoutKey&sectionid=2&scoutid=1'
517
+ FakeWeb.register_uri(:post, url, :body => '{"ok":true,"key":"KEY-HERE"}')
518
+ @member.myscout_link(@api, :badges).should == 'https://www.onlinescoutmanager.co.uk/parents/badges.php?sc=1&se=2&c=KEY-HERE'
519
+ end
520
+
521
+ it "Invalid" do
522
+ expect{ @member.myscout_link(@api, :invalid) }.to raise_error(Osm::ArgumentIsInvalid)
523
+ end
524
+
525
+ end
526
+
421
527
  end
422
528
 
423
529
  end