osm 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +32 -5
- data/README.md +16 -17
- data/lib/osm.rb +1 -1
- data/lib/osm/activity.rb +18 -0
- data/lib/osm/api.rb +3 -2
- data/lib/osm/evening.rb +51 -15
- data/lib/osm/event.rb +72 -15
- data/lib/osm/flexi_record.rb +114 -1
- data/lib/osm/grouping.rb +1 -1
- data/lib/osm/member.rb +118 -6
- data/lib/osm/register.rb +1 -1
- data/lib/osm/section.rb +8 -8
- data/osm.gemspec +1 -1
- data/spec/osm/activity_spec.rb +25 -0
- data/spec/osm/evening_spec.rb +54 -4
- data/spec/osm/event_spec.rb +76 -2
- data/spec/osm/flexi_record_spec.rb +225 -0
- data/spec/osm/member_spec.rb +212 -0
- data/spec/osm/section_spec.rb +6 -4
- data/version.rb +1 -1
- metadata +17 -17
data/lib/osm/grouping.rb
CHANGED
@@ -9,7 +9,7 @@ module Osm
|
|
9
9
|
# @!attribute [rw] name
|
10
10
|
# @return [String] the name of the grouping
|
11
11
|
# @!attribute [rw] active
|
12
|
-
# @return [Boolean]
|
12
|
+
# @return [Boolean] whether the grouping is active
|
13
13
|
# @!attribute [rw] points
|
14
14
|
# @return [Fixnum] the points awarded to the grouping
|
15
15
|
|
data/lib/osm/member.rb
CHANGED
@@ -73,7 +73,7 @@ module Osm
|
|
73
73
|
# @!attribute [rw] grouping_id
|
74
74
|
# @return [Fixnum] the grouping within the section that the member belongs to
|
75
75
|
# @!attribute [rw] grouping_leader
|
76
|
-
# @return [Fixnum]
|
76
|
+
# @return [Fixnum] whether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL)
|
77
77
|
# @!attribute [rw] joined
|
78
78
|
# @return [Date] when the member joined the section
|
79
79
|
# @!attribute [rw] age
|
@@ -127,12 +127,12 @@ module Osm
|
|
127
127
|
:custom1, :custom2, :custom3, :custom4, :custom5, :custom6, :custom7, :custom8, :custom9,
|
128
128
|
:grouping_id, :grouping_leader, :joined, :age, :joined_years
|
129
129
|
|
130
|
-
validates_numericality_of :id, :only_integer=>true, :greater_than=>0
|
130
|
+
validates_numericality_of :id, :only_integer=>true, :greater_than=>0, :unless => Proc.new { |r| r.id.nil? }
|
131
131
|
validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
|
132
132
|
validates_numericality_of :grouping_id, :only_integer=>true, :greater_than_or_equal_to=>-2
|
133
133
|
validates_numericality_of :grouping_leader, :only_integer=>true, :greater_than_or_equal_to=>0, :less_than_or_equal_to=>2
|
134
|
-
validates_numericality_of :joined_years, :only_integer=>true, :greater_than_or_equal_to=>-1
|
135
|
-
validates_numericality_of :joining_in_years, :only_integer=>true, :greater_than_or_equal_to=>0
|
134
|
+
validates_numericality_of :joined_years, :only_integer=>true, :greater_than_or_equal_to=>-1, :allow_nil=>true
|
135
|
+
validates_numericality_of :joining_in_years, :only_integer=>true, :greater_than_or_equal_to=>0, :allow_nil=>true
|
136
136
|
validates_presence_of :first_name
|
137
137
|
validates_presence_of :last_name
|
138
138
|
validates_presence_of :date_of_birth
|
@@ -199,7 +199,7 @@ module Osm
|
|
199
199
|
:grouping_id => Osm::to_i_or_nil(item['patrolid']),
|
200
200
|
:grouping_leader => Osm::to_i_or_nil(item['patrolleader']),
|
201
201
|
:joined => Osm::parse_date(item['joined']),
|
202
|
-
:age => item['age'],
|
202
|
+
:age => item['age'].gsub(' ', ''),
|
203
203
|
:joined_years => item['yrs'].to_i,
|
204
204
|
)
|
205
205
|
end
|
@@ -210,10 +210,122 @@ module Osm
|
|
210
210
|
|
211
211
|
|
212
212
|
# @!method initialize
|
213
|
-
# Initialize a new
|
213
|
+
# Initialize a new Member
|
214
214
|
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
215
215
|
|
216
216
|
|
217
|
+
# Create the user in OSM
|
218
|
+
# @param [Osm::Api] api The api to use to make the request
|
219
|
+
# @return [Boolan] whether the member was successfully added or not
|
220
|
+
def create(api)
|
221
|
+
raise ObjectIsInvalid, 'member is invalid' unless valid?
|
222
|
+
raise Error, 'the member already exists in OSM' unless id.nil?
|
223
|
+
|
224
|
+
data = api.perform_query("users.php?action=newMember", {
|
225
|
+
'firstname' => first_name,
|
226
|
+
'lastname' => last_name,
|
227
|
+
'dob' => date_of_birth.strftime(Osm::OSM_DATE_FORMAT),
|
228
|
+
'started' => started.strftime(Osm::OSM_DATE_FORMAT),
|
229
|
+
'startedsection' => joined.strftime(Osm::OSM_DATE_FORMAT),
|
230
|
+
'patrolid' => grouping_id,
|
231
|
+
'patrolleader' => grouping_leader,
|
232
|
+
'sectionid' => section_id,
|
233
|
+
'email1' => email1,
|
234
|
+
'email2' => email2,
|
235
|
+
'email3' => email3,
|
236
|
+
'email4' => email4,
|
237
|
+
'phone1' => phone1,
|
238
|
+
'phone2' => phone2,
|
239
|
+
'phone3' => phone3,
|
240
|
+
'phone4' => phone4,
|
241
|
+
'address' => address,
|
242
|
+
'address2' => address2,
|
243
|
+
'parents' => parents,
|
244
|
+
'notes' => notes,
|
245
|
+
'medical' => medical,
|
246
|
+
'religion' => religion,
|
247
|
+
'school' => school,
|
248
|
+
'ethnicity' => ethnicity,
|
249
|
+
'subs' => subs,
|
250
|
+
'custom1' => custom1,
|
251
|
+
'custom2' => custom2,
|
252
|
+
'custom3' => custom3,
|
253
|
+
'custom4' => custom4,
|
254
|
+
'custom5' => custom5,
|
255
|
+
'custom6' => custom6,
|
256
|
+
'custom7' => custom7,
|
257
|
+
'custom8' => custom8,
|
258
|
+
'custom9' => custom9,
|
259
|
+
})
|
260
|
+
|
261
|
+
if (data.is_a?(Hash) && (data['result'] == 'ok') && (data['scoutid'].to_i > 0))
|
262
|
+
self.id = data['scoutid'].to_i
|
263
|
+
# The cached members for the section will be out of date - remove them
|
264
|
+
Osm::Term.get_for_section(api, section_id).each do |term|
|
265
|
+
cache_delete(api, ['members', section_id, term.id])
|
266
|
+
end
|
267
|
+
return true
|
268
|
+
else
|
269
|
+
return false
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
# Update the user in OSM
|
274
|
+
# @param [Osm::Api] api The api to use to make the request
|
275
|
+
# @return [Boolan] whether the member was successfully updated or not
|
276
|
+
def update(api)
|
277
|
+
raise ObjectIsInvalid, 'member is invalid' unless valid?
|
278
|
+
|
279
|
+
values = {
|
280
|
+
'firstname' => first_name,
|
281
|
+
'lastname' => last_name,
|
282
|
+
'dob' => date_of_birth.strftime(Osm::OSM_DATE_FORMAT),
|
283
|
+
'started' => started.strftime(Osm::OSM_DATE_FORMAT),
|
284
|
+
'startedsection' => joined.strftime(Osm::OSM_DATE_FORMAT),
|
285
|
+
'patrolid' => grouping_id,
|
286
|
+
'patrolleader' => grouping_leader,
|
287
|
+
'email1' => email1,
|
288
|
+
'email2' => email2,
|
289
|
+
'email3' => email3,
|
290
|
+
'email4' => email4,
|
291
|
+
'phone1' => phone1,
|
292
|
+
'phone2' => phone2,
|
293
|
+
'phone3' => phone3,
|
294
|
+
'phone4' => phone4,
|
295
|
+
'address' => address,
|
296
|
+
'address2' => address2,
|
297
|
+
'parents' => parents,
|
298
|
+
'notes' => notes,
|
299
|
+
'medical' => medical,
|
300
|
+
'religion' => religion,
|
301
|
+
'school' => school,
|
302
|
+
'ethnicity' => ethnicity,
|
303
|
+
'subs' => subs,
|
304
|
+
'custom1' => custom1,
|
305
|
+
'custom2' => custom2,
|
306
|
+
'custom3' => custom3,
|
307
|
+
'custom4' => custom4,
|
308
|
+
'custom5' => custom5,
|
309
|
+
'custom6' => custom6,
|
310
|
+
'custom7' => custom7,
|
311
|
+
'custom8' => custom8,
|
312
|
+
'custom9' => custom9,
|
313
|
+
}
|
314
|
+
|
315
|
+
result = true
|
316
|
+
values.each do |column, value|
|
317
|
+
data = api.perform_query("users.php?action=updateMember&dateFormat=generic", {
|
318
|
+
'scoutid' => self.id,
|
319
|
+
'column' => column,
|
320
|
+
'value' => value,
|
321
|
+
'sectionid' => section_id,
|
322
|
+
})
|
323
|
+
result &= (data[column] == value.to_s)
|
324
|
+
end
|
325
|
+
|
326
|
+
return result
|
327
|
+
end
|
328
|
+
|
217
329
|
# Get the years element of this scout's age
|
218
330
|
# @return [Fixnum] the number of years this scout has been alive
|
219
331
|
def age_years
|
data/lib/osm/register.rb
CHANGED
@@ -80,7 +80,7 @@ module Osm
|
|
80
80
|
# @option data [String] :attendance what to mark the attendance as, one of "Yes", "No" or "Absent"
|
81
81
|
# @option data [Fixnum, Array<Fixnum>, Osm::Member, Array<Osm::Member>] :members the members (or their ids) to update
|
82
82
|
# @option data [Array<Hash>] :completed_badge_requirements (optional) the badge requirements to mark as completed, selected from the Hash returned by the get_badge_requirements_for_evening method
|
83
|
-
# @return [Boolean]
|
83
|
+
# @return [Boolean] whether the update succedded
|
84
84
|
def self.update_attendance(data={})
|
85
85
|
raise ArgumentIsInvalid, ':attendance is invalid' unless ['Yes', 'No', 'Absent'].include?(data[:attendance])
|
86
86
|
raise ArgumentIsInvalid, ':section is missing' if data[:section].nil?
|
data/lib/osm/section.rb
CHANGED
@@ -45,8 +45,8 @@ module Osm
|
|
45
45
|
# @return [Boolean] whether the section uses the Payments part of My.SCOUT
|
46
46
|
# @!attribute [rw] myscout_emails
|
47
47
|
# @return [Hash of Symbol to Boolean] which email addresses are linked to MyScout for each Member
|
48
|
-
# @!attribute [rw]
|
49
|
-
# @return [String] which email address to send My.SCOUT emails as
|
48
|
+
# @!attribute [rw] myscout_email_address_from
|
49
|
+
# @return [String] which email address to send My.SCOUT emails as coming from
|
50
50
|
# @!attribute [rw] myscout_email_address_copy
|
51
51
|
# @return [String] which email address to send copys of My.SCOUT emails to
|
52
52
|
# @!attribute [rw] myscout_badges_partial
|
@@ -82,9 +82,9 @@ module Osm
|
|
82
82
|
attribute :myscout_badges, :type => Boolean
|
83
83
|
attribute :myscout_programme, :type => Boolean
|
84
84
|
attribute :myscout_payments, :type => Boolean
|
85
|
-
attribute :myscout_emails, :default => {}
|
86
|
-
attribute :
|
87
|
-
attribute :myscout_email_address_copy, :type => String
|
85
|
+
attribute :myscout_emails, :default => {}
|
86
|
+
attribute :myscout_email_address_from, :type => String, :default => ''
|
87
|
+
attribute :myscout_email_address_copy, :type => String, :default => ''
|
88
88
|
attribute :myscout_badges_partial, :type => Boolean
|
89
89
|
attribute :myscout_programme_summary, :type => Boolean
|
90
90
|
attribute :myscout_event_reminder_count, :type => Integer
|
@@ -97,7 +97,7 @@ module Osm
|
|
97
97
|
:gocardless, :myscout_events_expires, :myscout_badges_expires,
|
98
98
|
:myscout_programme_expires, :myscout_events, :myscout_badges,
|
99
99
|
:myscout_programme, :myscout_payments, :myscout_emails,
|
100
|
-
:
|
100
|
+
:myscout_email_address_from, :myscout_email_address_copy,
|
101
101
|
:myscout_badges_partial, :myscout_programme_summary,
|
102
102
|
:myscout_event_reminder_count, :myscout_event_reminder_frequency,
|
103
103
|
:myscout_payment_reminder_count, :myscout_payment_reminder_frequency
|
@@ -205,8 +205,8 @@ module Osm
|
|
205
205
|
:myscout_programme => myscout_data['programme'] == 1,
|
206
206
|
:myscout_payments => myscout_data['payments'] == 1,
|
207
207
|
:myscout_emails => (myscout_data['emails'] || {}).inject({}) { |n,(k,v)| n[k.to_sym] = v.eql?('true'); n},
|
208
|
-
:
|
209
|
-
:myscout_email_address_copy => myscout_data['emailAddressCopy'],
|
208
|
+
:myscout_email_address_from => myscout_data['emailAddress'] ? myscout_data['emailAddress'] : '',
|
209
|
+
:myscout_email_address_copy => myscout_data['emailAddressCopy'] ? myscout_data['emailAddressCopy'] : '',
|
210
210
|
:myscout_badges_partial => myscout_data['badgesPartial'] == 1,
|
211
211
|
:myscout_programme_summary => myscout_data['programmeSummary'] == 1,
|
212
212
|
:myscout_event_reminder_count => myscout_data['eventRemindCount'].to_i,
|
data/osm.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Osm::VERSION
|
8
8
|
s.authors = ['Robert Gauld']
|
9
9
|
s.email = ['robert@robertgauld.co.uk']
|
10
|
-
s.homepage = ''
|
10
|
+
s.homepage = 'https://github.com/robertgauld/osm'
|
11
11
|
s.summary = %q{Use the Online Scout Manager API}
|
12
12
|
s.description = %q{Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk) to retrieve and save data.}
|
13
13
|
|
data/spec/osm/activity_spec.rb
CHANGED
@@ -93,4 +93,29 @@ describe "Using The API" do
|
|
93
93
|
activity.valid?.should be_true
|
94
94
|
end
|
95
95
|
|
96
|
+
|
97
|
+
it "Add activity to programme (succeded)" do
|
98
|
+
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
|
99
|
+
post_data = {
|
100
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
101
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
102
|
+
'userid' => 'user_id',
|
103
|
+
'secret' => 'secret',
|
104
|
+
'meetingdate' => '2000-01-02',
|
105
|
+
'sectionid' => 1,
|
106
|
+
'activityid' => 2,
|
107
|
+
'notes' => 'Notes',
|
108
|
+
}
|
109
|
+
|
110
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
|
111
|
+
activity = Osm::Activity.new(:id => 2)
|
112
|
+
activity.add_to_programme(@api, 1, Date.new(2000, 1, 2), 'Notes').should be_true
|
113
|
+
end
|
114
|
+
|
115
|
+
it "Add activity to programme (failed)" do
|
116
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
|
117
|
+
activity = Osm::Activity.new(:id => 2)
|
118
|
+
activity.add_to_programme(@api, 1, Date.new(2000, 1, 2), 'Notes').should be_false
|
119
|
+
end
|
120
|
+
|
96
121
|
end
|
data/spec/osm/evening_spec.rb
CHANGED
@@ -88,14 +88,37 @@ describe "Evening" do
|
|
88
88
|
'meetingdate' => '2000-01-02',
|
89
89
|
'sectionid' => 1,
|
90
90
|
'activityid' => -1,
|
91
|
+
'start' => '2000-01-02',
|
92
|
+
'starttime' => '11:11',
|
93
|
+
'endtime' => '22:22',
|
94
|
+
'title' => 'Title',
|
91
95
|
}
|
92
96
|
|
93
97
|
Osm::Term.stub(:get_for_section) { [] }
|
94
98
|
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
|
95
|
-
Osm::Evening.create(@api,
|
99
|
+
Osm::Evening.create(@api, {
|
100
|
+
:section_id => 1,
|
101
|
+
:meeting_date => Date.new(2000, 1, 2),
|
102
|
+
:start_time => '11:11',
|
103
|
+
:finish_time => '22:22',
|
104
|
+
:title => 'Title',
|
105
|
+
}).should be_true
|
96
106
|
end
|
97
107
|
|
98
108
|
it "Create an evening (failed)" do
|
109
|
+
Osm::Term.stub(:get_for_section) { [] }
|
110
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'[]'}) }
|
111
|
+
Osm::Evening.create(@api, {
|
112
|
+
:section_id => 1,
|
113
|
+
:meeting_date => Date.new(2000, 1, 2),
|
114
|
+
:start_time => '11:11',
|
115
|
+
:finish_time => '22:22',
|
116
|
+
:title => 'Title',
|
117
|
+
}).should be_false
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
it "Add activity to evening (succeded)" do
|
99
122
|
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
|
100
123
|
post_data = {
|
101
124
|
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
@@ -104,12 +127,23 @@ describe "Evening" do
|
|
104
127
|
'secret' => 'secret',
|
105
128
|
'meetingdate' => '2000-01-02',
|
106
129
|
'sectionid' => 1,
|
107
|
-
'activityid' =>
|
130
|
+
'activityid' => 2,
|
131
|
+
'notes' => 'Notes',
|
108
132
|
}
|
109
133
|
|
110
134
|
Osm::Term.stub(:get_for_section) { [] }
|
111
|
-
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":
|
112
|
-
Osm::
|
135
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
|
136
|
+
activity = Osm::Activity.new(:id => 2, :title => 'Title')
|
137
|
+
evening = Osm::Evening.new(:section_id => 1, :meeting_date => Date.new(2000, 1, 2))
|
138
|
+
evening.add_activity(@api, activity, 'Notes').should be_true
|
139
|
+
evening.activities[0].activity_id.should == 2
|
140
|
+
end
|
141
|
+
|
142
|
+
it "Add activity to evening (failed)" do
|
143
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
|
144
|
+
activity = Osm::Activity.new(:id => 2, :title => 'Title')
|
145
|
+
evening = Osm::Evening.new(:section_id => 1, :meeting_date => Date.new(2000, 1, 2))
|
146
|
+
evening.add_activity(@api, activity, 'Notes').should be_false
|
113
147
|
end
|
114
148
|
|
115
149
|
|
@@ -154,5 +188,21 @@ describe "Evening" do
|
|
154
188
|
expect{ evening.update(@api) }.to raise_error(Osm::ObjectIsInvalid)
|
155
189
|
end
|
156
190
|
|
191
|
+
|
192
|
+
it "Delete an evening" do
|
193
|
+
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=deleteEvening&eveningid=1§ionid=2'
|
194
|
+
post_data = {
|
195
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
196
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
197
|
+
'userid' => 'user_id',
|
198
|
+
'secret' => 'secret',
|
199
|
+
}
|
200
|
+
Osm::Term.stub(:get_for_section) { [] }
|
201
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>''}) }
|
202
|
+
|
203
|
+
evening = Osm::Evening.new(:id=>1, :section_id=>2)
|
204
|
+
evening.delete(@api).should be_true
|
205
|
+
end
|
206
|
+
|
157
207
|
end
|
158
208
|
end
|
data/spec/osm/event_spec.rb
CHANGED
@@ -134,7 +134,7 @@ describe "Event" do
|
|
134
134
|
event.reminders.should == false
|
135
135
|
event.columns[0].id.should == 'f_1'
|
136
136
|
event.columns[0].name.should == 'Name'
|
137
|
-
event.columns[0].
|
137
|
+
event.columns[0].label.should == 'Label'
|
138
138
|
event.valid?.should be_true
|
139
139
|
end
|
140
140
|
|
@@ -434,7 +434,10 @@ describe "Event" do
|
|
434
434
|
event = Osm::Event.new(:id => 2, :section_id => 1)
|
435
435
|
event.should_not be_nil
|
436
436
|
event.add_column(@api, 'Test name', 'Test label').should be_true
|
437
|
-
event.columns
|
437
|
+
column = event.columns[0]
|
438
|
+
column.id.should == 'f_1'
|
439
|
+
column.name.should == 'Test name'
|
440
|
+
column.label.should == 'Test label'
|
438
441
|
end
|
439
442
|
|
440
443
|
it "Add column (failed)" do
|
@@ -445,6 +448,77 @@ describe "Event" do
|
|
445
448
|
event.add_column(@api, 'Test name', 'Test label').should be_false
|
446
449
|
end
|
447
450
|
|
451
|
+
|
452
|
+
it "Update column (succeded)" do
|
453
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=renameColumn§ionid=1&eventid=2'
|
454
|
+
post_data = {
|
455
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
456
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
457
|
+
'userid' => 'user_id',
|
458
|
+
'secret' => 'secret',
|
459
|
+
'columnId' => 'f_1',
|
460
|
+
'columnName' => 'New name',
|
461
|
+
'pL' => 'New label',
|
462
|
+
}
|
463
|
+
body = {
|
464
|
+
'eventid' => '2',
|
465
|
+
'config' => '[{"id":"f_1","name":"New name","pL":"New label"}]'
|
466
|
+
}
|
467
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>body.to_json}) }
|
468
|
+
|
469
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
470
|
+
event.columns = [Osm::Event::Column.new(:id => 'f_1', :event => event)]
|
471
|
+
column = event.columns[0]
|
472
|
+
column.name = 'New name'
|
473
|
+
column.label = 'New label'
|
474
|
+
|
475
|
+
column.update(@api).should be_true
|
476
|
+
|
477
|
+
column.name.should == 'New name'
|
478
|
+
column.label.should == 'New label'
|
479
|
+
event.columns[0].name.should == 'New name'
|
480
|
+
event.columns[0].label.should == 'New label'
|
481
|
+
end
|
482
|
+
|
483
|
+
it "Update column (failed)" do
|
484
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"config":"[]"}'}) }
|
485
|
+
|
486
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
487
|
+
column = Osm::Event::Column.new(:id => 'f_1', :event => event)
|
488
|
+
event.columns = [column]
|
489
|
+
column.update(@api).should be_false
|
490
|
+
end
|
491
|
+
|
492
|
+
|
493
|
+
it "Delete column (succeded)" do
|
494
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=deleteColumn§ionid=1&eventid=2'
|
495
|
+
post_data = {
|
496
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
497
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
498
|
+
'userid' => 'user_id',
|
499
|
+
'secret' => 'secret',
|
500
|
+
'columnId' => 'f_1'
|
501
|
+
}
|
502
|
+
|
503
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"eventid":"2","config":"[]"}'}) }
|
504
|
+
|
505
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
506
|
+
column = Osm::Event::Column.new(:id => 'f_1', :event => event)
|
507
|
+
event.columns = [column]
|
508
|
+
|
509
|
+
column.delete(@api).should be_true
|
510
|
+
event.columns.should == []
|
511
|
+
end
|
512
|
+
|
513
|
+
it "Delete column (failed)" do
|
514
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"config":"[{\"id\":\"f_1\"}]"}'}) }
|
515
|
+
|
516
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
517
|
+
column = Osm::Event::Column.new(:id => 'f_1', :event => event)
|
518
|
+
event.columns = [column]
|
519
|
+
column.delete(@api).should be_false
|
520
|
+
end
|
521
|
+
|
448
522
|
end
|
449
523
|
|
450
524
|
|
@@ -85,6 +85,190 @@ describe "Flexi Record" do
|
|
85
85
|
fields[3].id.should == 'f_2'
|
86
86
|
end
|
87
87
|
|
88
|
+
it "Add field (success)" do
|
89
|
+
url = "https://www.onlinescoutmanager.co.uk/extras.php?action=addColumn§ionid=1&extraid=2"
|
90
|
+
|
91
|
+
post_data = {
|
92
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
93
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
94
|
+
'userid' => 'user_id',
|
95
|
+
'secret' => 'secret',
|
96
|
+
'columnName' => 'name',
|
97
|
+
}
|
98
|
+
|
99
|
+
data = {
|
100
|
+
"extraid" => "2",
|
101
|
+
"sectionid" => "1",
|
102
|
+
"name" => "A Flexi Record",
|
103
|
+
"config" => "[{\"id\":\"f_1\",\"name\":\"name\",\"width\":\"150\"}]",
|
104
|
+
"total" => "none",
|
105
|
+
"extrafields" => "[]",
|
106
|
+
"structure" => [
|
107
|
+
{
|
108
|
+
"rows" => [
|
109
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
110
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
111
|
+
],
|
112
|
+
"noscroll" => true
|
113
|
+
},
|
114
|
+
{"rows" => [
|
115
|
+
{"name" => "name","field" => "f_1","width" => "150px","editable" => true},
|
116
|
+
]}
|
117
|
+
]
|
118
|
+
}
|
119
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
120
|
+
|
121
|
+
Osm::FlexiRecord.add_field(@api, 1, 2, 'name').should be_true
|
122
|
+
end
|
123
|
+
|
124
|
+
it "Add field (failure)" do
|
125
|
+
data = {
|
126
|
+
"extraid" => "2",
|
127
|
+
"sectionid" => "1",
|
128
|
+
"name" => "A Flexi Record",
|
129
|
+
"config" => "[]",
|
130
|
+
"total" => "none",
|
131
|
+
"extrafields" => "[]",
|
132
|
+
"structure" => [
|
133
|
+
{
|
134
|
+
"rows" => [
|
135
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
136
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
137
|
+
],
|
138
|
+
"noscroll" => true
|
139
|
+
},
|
140
|
+
{"rows" => [
|
141
|
+
]}
|
142
|
+
]
|
143
|
+
}
|
144
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
145
|
+
|
146
|
+
Osm::FlexiRecord.add_field(@api, 1, 2, 'name').should be_false
|
147
|
+
end
|
148
|
+
|
149
|
+
it "Update field (success)" do
|
150
|
+
url = "https://www.onlinescoutmanager.co.uk/extras.php?action=renameColumn§ionid=1&extraid=2"
|
151
|
+
|
152
|
+
post_data = {
|
153
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
154
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
155
|
+
'userid' => 'user_id',
|
156
|
+
'secret' => 'secret',
|
157
|
+
'columnId' => 'f_1',
|
158
|
+
'columnName' => 'name',
|
159
|
+
}
|
160
|
+
|
161
|
+
data = {
|
162
|
+
"extraid" => "2",
|
163
|
+
"sectionid" => "1",
|
164
|
+
"name" => "A Flexi Record",
|
165
|
+
"config" => "[{\"id\":\"f_1\",\"name\":\"name\",\"width\":\"150\"}]",
|
166
|
+
"total" => "none",
|
167
|
+
"extrafields" => "[]",
|
168
|
+
"structure" => [
|
169
|
+
{
|
170
|
+
"rows" => [
|
171
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
172
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
173
|
+
],
|
174
|
+
"noscroll" => true
|
175
|
+
},
|
176
|
+
{"rows" => [
|
177
|
+
{"name" => "name","field" => "f_1","width" => "150px","editable" => true},
|
178
|
+
]}
|
179
|
+
]
|
180
|
+
}
|
181
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
182
|
+
|
183
|
+
Osm::FlexiRecord.update_field(@api, 1, 2, 'f_1', 'name').should be_true
|
184
|
+
end
|
185
|
+
|
186
|
+
it "Update field (failure)" do
|
187
|
+
data = {
|
188
|
+
"extraid" => "2",
|
189
|
+
"sectionid" => "1",
|
190
|
+
"name" => "A Flexi Record",
|
191
|
+
"config" => "[]",
|
192
|
+
"total" => "none",
|
193
|
+
"extrafields" => "[]",
|
194
|
+
"structure" => [
|
195
|
+
{
|
196
|
+
"rows" => [
|
197
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
198
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
199
|
+
],
|
200
|
+
"noscroll" => true
|
201
|
+
},
|
202
|
+
{"rows" => [
|
203
|
+
]}
|
204
|
+
]
|
205
|
+
}
|
206
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
207
|
+
|
208
|
+
Osm::FlexiRecord.update_field(@api, 1, 2, 'f_1', 'name').should be_false
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
it "Delete field (success)" do
|
213
|
+
url = "https://www.onlinescoutmanager.co.uk/extras.php?action=deleteColumn§ionid=1&extraid=2"
|
214
|
+
|
215
|
+
post_data = {
|
216
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
217
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
218
|
+
'userid' => 'user_id',
|
219
|
+
'secret' => 'secret',
|
220
|
+
'columnId' => 'f_1',
|
221
|
+
}
|
222
|
+
|
223
|
+
data = {
|
224
|
+
"extraid" => "2",
|
225
|
+
"sectionid" => "1",
|
226
|
+
"name" => "A Flexi Record",
|
227
|
+
"config" => "[]",
|
228
|
+
"total" => "none",
|
229
|
+
"extrafields" => "[]",
|
230
|
+
"structure" => [
|
231
|
+
{
|
232
|
+
"rows" => [
|
233
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
234
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
235
|
+
],
|
236
|
+
"noscroll" => true
|
237
|
+
},
|
238
|
+
{"rows" => []}
|
239
|
+
]
|
240
|
+
}
|
241
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
242
|
+
|
243
|
+
Osm::FlexiRecord.delete_field(@api, 1, 2, 'f_1').should be_true
|
244
|
+
end
|
245
|
+
|
246
|
+
it "Delete field (failure)" do
|
247
|
+
data = {
|
248
|
+
"extraid" => "2",
|
249
|
+
"sectionid" => "1",
|
250
|
+
"name" => "A Flexi Record",
|
251
|
+
"config" => "[{\"id\":\"f_1\",\"name\":\"name\",\"width\":\"150\"}]",
|
252
|
+
"total" => "none",
|
253
|
+
"extrafields" => "[]",
|
254
|
+
"structure" => [
|
255
|
+
{
|
256
|
+
"rows" => [
|
257
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
258
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
259
|
+
],
|
260
|
+
"noscroll" => true
|
261
|
+
},
|
262
|
+
{"rows" => [
|
263
|
+
]}
|
264
|
+
]
|
265
|
+
}
|
266
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
267
|
+
|
268
|
+
Osm::FlexiRecord.delete_field(@api, 1, 2, 'f_1').should be_false
|
269
|
+
end
|
270
|
+
|
271
|
+
|
88
272
|
it "Fetch Data" do
|
89
273
|
data = {
|
90
274
|
'identifier' => 'scoutid',
|
@@ -125,6 +309,47 @@ describe "Flexi Record" do
|
|
125
309
|
end
|
126
310
|
|
127
311
|
|
312
|
+
it "Update data (success)" do
|
313
|
+
url = "https://www.onlinescoutmanager.co.uk/extras.php?action=updateScout"
|
314
|
+
|
315
|
+
post_data = {
|
316
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
317
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
318
|
+
'userid' => 'user_id',
|
319
|
+
'secret' => 'secret',
|
320
|
+
'termid' => 1,
|
321
|
+
'scoutid' => 2,
|
322
|
+
'column' => 'f_1',
|
323
|
+
'value' => 'value',
|
324
|
+
'sectionid' => 3,
|
325
|
+
'extraid' => 4,
|
326
|
+
}
|
327
|
+
|
328
|
+
data = {
|
329
|
+
'items' => [
|
330
|
+
{'f_1' => 'value', 'scoutid' => '2'},
|
331
|
+
]
|
332
|
+
}
|
333
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
334
|
+
Osm::Term.stub(:get_current_term_for_section) { Osm::Term.new(:id => 1) }
|
335
|
+
|
336
|
+
Osm::FlexiRecord.update_data(@api, 3, 4, 2, 'f_1', 'value').should be_true
|
337
|
+
end
|
338
|
+
|
339
|
+
it "Update data (failed)" do
|
340
|
+
data = {
|
341
|
+
'items' => [
|
342
|
+
{'f_1' => 'old value', 'scoutid' => '2'},
|
343
|
+
]
|
344
|
+
}
|
345
|
+
|
346
|
+
HTTParty.stub(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
347
|
+
Osm::Term.stub(:get_current_term_for_section) { Osm::Term.new(:id => 1) }
|
348
|
+
|
349
|
+
Osm::FlexiRecord.update_data(@api, 3, 4, 2, 'f_1', 'value').should be_false
|
350
|
+
end
|
351
|
+
|
352
|
+
|
128
353
|
it "Handles the total row" do
|
129
354
|
data = {
|
130
355
|
'identifier' => 'scoutid',
|