osm 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -2
- data/Guardfile +1 -1
- data/lib/osm.rb +1 -1
- data/lib/osm/event.rb +69 -9
- data/lib/osm/meeting.rb +76 -6
- data/spec/osm/event_spec.rb +42 -3
- data/spec/osm/meeting_spec.rb +86 -13
- data/version.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
## Version 1.0.6
|
2
2
|
|
3
|
-
*
|
3
|
+
* Add badge\_links to Meeting
|
4
|
+
* Event.add\_column method gains a required attirbute (default false) to control whether parents are required to enter something
|
5
|
+
* Event::Column gains parent\_required attribute (default false)
|
6
|
+
* Event::Attendance gains get\_audit\_trail(api) method
|
4
7
|
|
5
8
|
## Version 1.0.5
|
6
9
|
|
7
|
-
* Fix undefined method
|
10
|
+
* Fix undefined method youth\_section? within Model.require\_ability\_to
|
8
11
|
|
9
12
|
## Version 1.0.4
|
10
13
|
|
data/Guardfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
guard 'rspec' do
|
4
|
+
guard 'rspec', all_on_start: true, all_after_pass: true do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
7
|
watch(%r{^lib/([^/]+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
|
data/lib/osm.rb
CHANGED
@@ -94,7 +94,7 @@ module Osm
|
|
94
94
|
def self.parse_datetime(date_time)
|
95
95
|
return nil if date_time.nil? || date_time.empty?
|
96
96
|
begin
|
97
|
-
return DateTime.strptime(
|
97
|
+
return DateTime.strptime(date_time, OSM_DATETIME_FORMAT)
|
98
98
|
rescue ArgumentError
|
99
99
|
return nil
|
100
100
|
end
|
data/lib/osm/event.rb
CHANGED
@@ -267,6 +267,7 @@ module Osm
|
|
267
267
|
'No' => :no,
|
268
268
|
'Invited' => :invited,
|
269
269
|
'Show in My.SCOUT' => :shown,
|
270
|
+
'Reserved' => :reserved,
|
270
271
|
}
|
271
272
|
|
272
273
|
attendance = []
|
@@ -297,15 +298,17 @@ module Osm
|
|
297
298
|
# @param [Osm::Api] api The api to use to make the request
|
298
299
|
# @param [String] label The label for the field in OSM
|
299
300
|
# @param [String] name The label for the field in My.SCOUT (if this is blank then parents can't edit it)
|
301
|
+
# @param [Boolean] required Whether the parent is required to enter something
|
300
302
|
# @return [Boolean] whether the update succedded
|
301
303
|
# @raise [Osm::ArgumentIsInvalid] If the name is blank
|
302
|
-
def add_column(api, name, label='')
|
304
|
+
def add_column(api, name, label='', required=false)
|
303
305
|
require_ability_to(api, :write, :events, section_id)
|
304
306
|
raise Osm::ArgumentIsInvalid, 'name is invalid' if name.blank?
|
305
307
|
|
306
308
|
data = api.perform_query("events.php?action=addColumn§ionid=#{section_id}&eventid=#{id}", {
|
307
309
|
'columnName' => name,
|
308
|
-
'parentLabel' => label
|
310
|
+
'parentLabel' => label,
|
311
|
+
'parentRequire' => (required ? 1 : 0),
|
309
312
|
})
|
310
313
|
|
311
314
|
# The cached events for the section will be out of date - remove them
|
@@ -396,7 +399,7 @@ module Osm
|
|
396
399
|
column_data = ActiveSupport::JSON.decode(event_data['config'] || '[]')
|
397
400
|
column_data = [] unless column_data.is_a?(Array)
|
398
401
|
column_data.each do |field|
|
399
|
-
columns.push Column.new(:id => field['id'], :name => field['name'], :label => field['pL'], :event => event)
|
402
|
+
columns.push Column.new(:id => field['id'], :name => field['name'], :label => field['pL'], :parent_required => field['pR'].to_s.eql?('1'), :event => event)
|
400
403
|
end
|
401
404
|
event.columns = columns
|
402
405
|
return event
|
@@ -411,15 +414,18 @@ module Osm
|
|
411
414
|
# @return [String] name for the column (displayed in OSM)
|
412
415
|
# @!attribute [rw] label
|
413
416
|
# @return [String] label to display in My.SCOUT ("" prevents display in My.SCOUT)
|
417
|
+
# @!attribute [rw] parent_required
|
418
|
+
# @return [Boolean] whether the parent is required to enter something
|
414
419
|
# @!attriute [rw] event
|
415
420
|
# @return [Osm::Event] the event that this column belongs to
|
416
421
|
|
417
422
|
attribute :id, :type => String
|
418
423
|
attribute :name, :type => String
|
419
424
|
attribute :label, :type => String, :default => ''
|
425
|
+
attribute :parent_required, :type => Boolean, :default => false
|
420
426
|
attribute :event
|
421
427
|
|
422
|
-
attr_accessible :id, :name, :label, :event
|
428
|
+
attr_accessible :id, :name, :label, :parent_required, :event
|
423
429
|
|
424
430
|
validates_presence_of :id
|
425
431
|
validates_presence_of :name
|
@@ -439,12 +445,13 @@ module Osm
|
|
439
445
|
data = api.perform_query("events.php?action=renameColumn§ionid=#{event.section_id}&eventid=#{event.id}", {
|
440
446
|
'columnId' => id,
|
441
447
|
'columnName' => name,
|
442
|
-
'pL' => label
|
448
|
+
'pL' => label,
|
449
|
+
'pR' => (parent_required ? 1 : 0),
|
443
450
|
})
|
444
451
|
|
445
452
|
(ActiveSupport::JSON.decode(data['config']) || []).each do |i|
|
446
453
|
if i['id'] == id
|
447
|
-
if i['name'].eql?(name) && (i['pL'].nil? || i['pL'].eql?(label))
|
454
|
+
if i['name'].eql?(name) && (i['pL'].nil? || i['pL'].eql?(label)) && (i['pR'].eql?('1') == parent_required)
|
448
455
|
reset_changed_attributes
|
449
456
|
# The cached event will be out of date - remove it
|
450
457
|
cache_delete(api, ['event', event.id])
|
@@ -513,7 +520,7 @@ module Osm
|
|
513
520
|
# @!attribute [rw] date_of_birth
|
514
521
|
# @return [Date] the member's date of birth
|
515
522
|
# @!attribute [rw] attending
|
516
|
-
# @return [Symbol] whether the member is attending (either :yes, :no, :invited, :shown or nil)
|
523
|
+
# @return [Symbol] whether the member is attending (either :yes, :no, :invited, :shown, :reserved or nil)
|
517
524
|
# @!attribute [rw] payments
|
518
525
|
# @return [Hash] keys are the payment's id, values are the payment state
|
519
526
|
# @!attribute [rw] payment_control
|
@@ -545,7 +552,7 @@ module Osm
|
|
545
552
|
validates_presence_of :last_name
|
546
553
|
validates_presence_of :date_of_birth
|
547
554
|
validates_inclusion_of :payment_control, :in => [:manual, :automatic, nil]
|
548
|
-
validates_inclusion_of :attending, :in => [:yes, :no, :invited, :shown, nil]
|
555
|
+
validates_inclusion_of :attending, :in => [:yes, :no, :invited, :shown, :reserved, nil]
|
549
556
|
|
550
557
|
|
551
558
|
# @!method initialize
|
@@ -575,6 +582,7 @@ module Osm
|
|
575
582
|
:no => 'No',
|
576
583
|
:invited => 'Invited',
|
577
584
|
:shown => 'Show in My.SCOUT',
|
585
|
+
:reserved => 'Reserved',
|
578
586
|
}
|
579
587
|
|
580
588
|
updated = true
|
@@ -622,6 +630,56 @@ module Osm
|
|
622
630
|
return updated
|
623
631
|
end
|
624
632
|
|
633
|
+
# Get audit trail
|
634
|
+
# @param [Osm::Api] api The api to use to make the request
|
635
|
+
# @!macro options_get
|
636
|
+
# @return [Array<Hash>]
|
637
|
+
def get_audit_trail(api, options={})
|
638
|
+
require_ability_to(api, :read, :events, event.section_id, options)
|
639
|
+
cache_key = ['event\_attendance\_audit', event.id, member_id]
|
640
|
+
|
641
|
+
if !options[:no_cache] && cache_exist?(api, cache_key)
|
642
|
+
return cache_read(api, cache_key)
|
643
|
+
end
|
644
|
+
|
645
|
+
data = api.perform_query("events.php?action=getEventAudit§ionid=#{event.section_id}&scoutid=#{member_id}&eventid=#{event.id}")
|
646
|
+
data ||= []
|
647
|
+
|
648
|
+
attending_values = {
|
649
|
+
'Yes' => :yes,
|
650
|
+
'No' => :no,
|
651
|
+
'Invited' => :invited,
|
652
|
+
'Show in My.SCOUT' => :shown,
|
653
|
+
'Reserved' => :reserved,
|
654
|
+
}
|
655
|
+
|
656
|
+
trail = []
|
657
|
+
data.each do |item|
|
658
|
+
this_item = {
|
659
|
+
:at => DateTime.strptime(item['date'], '%d/%m/%Y %H:%M'),
|
660
|
+
:by => item['updatedby'].strip,
|
661
|
+
:type => item['type'].to_sym,
|
662
|
+
:description => item['desc'],
|
663
|
+
:event_id => event.id,
|
664
|
+
:member_id => member_id,
|
665
|
+
:event_attendance => self,
|
666
|
+
}
|
667
|
+
if this_item[:type].eql?(:detail)
|
668
|
+
results = this_item[:description].match(/\ASet '(?<label>.+)' to '(?<value>.+)'\Z/)
|
669
|
+
this_item[:label] = results[:label]
|
670
|
+
this_item[:value] = results[:value]
|
671
|
+
end
|
672
|
+
if this_item[:type].eql?(:attendance)
|
673
|
+
results = this_item[:description].match(/\AAttendance: (?<attending>.+)\Z/)
|
674
|
+
this_item[:attendance] = attending_values[results[:attending]]
|
675
|
+
end
|
676
|
+
trail.push this_item
|
677
|
+
end
|
678
|
+
|
679
|
+
cache_write(api, cache_key, trail)
|
680
|
+
return trail
|
681
|
+
end
|
682
|
+
|
625
683
|
# @! method automatic_payments?
|
626
684
|
# Check wether payments are made automatically for this member
|
627
685
|
# @return [Boolean]
|
@@ -645,8 +703,10 @@ module Osm
|
|
645
703
|
# @return [Boolean]
|
646
704
|
# @! method is_shown?
|
647
705
|
# Check wether the member can see the event in My.SCOUT
|
706
|
+
# @! method is_reserved?
|
707
|
+
# Check wether the member has reserved a space when one becomes availible
|
648
708
|
# @return [Boolean]
|
649
|
-
[:attending, :not_attending, :invited, :shown].each do |attending_type|
|
709
|
+
[:attending, :not_attending, :invited, :shown, :reserved].each do |attending_type|
|
650
710
|
define_method "is_#{attending_type}?" do
|
651
711
|
attending == attending_type
|
652
712
|
end
|
data/lib/osm/meeting.rb
CHANGED
@@ -2,6 +2,7 @@ module Osm
|
|
2
2
|
|
3
3
|
class Meeting < Osm::Model
|
4
4
|
class Activity; end # Ensure the constant exists for the validators
|
5
|
+
class BadgeLink; end # Ensure the constant exists for the validators
|
5
6
|
|
6
7
|
# @!attribute [rw] id
|
7
8
|
# @return [Fixnum] the id of the meeting
|
@@ -23,6 +24,8 @@ module Osm
|
|
23
24
|
# @return [Date] the date of the meeting
|
24
25
|
# @!attribute [rw] activities
|
25
26
|
# @return [Array<Activity>] list of activities being done during the meeting
|
27
|
+
# @!attribute [rw] badge_links
|
28
|
+
# @return [Array<BadgeLink>] list of badge links added to the meeting
|
26
29
|
# @!attribute [rw] start_time
|
27
30
|
# @return [String] the start time (hh:mm)
|
28
31
|
# @!attribute [rw] finish_time
|
@@ -40,8 +43,9 @@ module Osm
|
|
40
43
|
attribute :start_time, :type => String
|
41
44
|
attribute :finish_time, :type => String
|
42
45
|
attribute :activities, :default => []
|
46
|
+
attribute :badge_links, :default => []
|
43
47
|
|
44
|
-
attr_accessible :id, :section_id, :title, :notes_for_parents, :games, :pre_notes, :post_notes, :leaders, :date, :activities, :start_time, :finish_time
|
48
|
+
attr_accessible :id, :section_id, :title, :notes_for_parents, :games, :pre_notes, :post_notes, :leaders, :date, :activities, :start_time, :finish_time, :badge_links
|
45
49
|
|
46
50
|
validates_numericality_of :id, :only_integer=>true, :greater_than=>0
|
47
51
|
validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
|
@@ -49,8 +53,8 @@ module Osm
|
|
49
53
|
validates_presence_of :date
|
50
54
|
validates_format_of :start_time, :with => Osm::OSM_TIME_REGEX, :message => 'is not in the correct format (HH:MM)', :allow_blank => true
|
51
55
|
validates_format_of :finish_time, :with => Osm::OSM_TIME_REGEX, :message => 'is not in the correct format (HH:MM)', :allow_blank => true
|
52
|
-
|
53
56
|
validates :activities, :array_of => {:item_type => Osm::Meeting::Activity, :item_valid => true}
|
57
|
+
validates :badge_links, :array_of => {:item_type => Osm::Meeting::BadgeLink, :item_valid => true}
|
54
58
|
|
55
59
|
# @!method initialize
|
56
60
|
# Initialize a new Meeting
|
@@ -79,6 +83,7 @@ module Osm
|
|
79
83
|
data = {'items'=>[],'activities'=>{}} if data.is_a? Array
|
80
84
|
items = data['items'] || []
|
81
85
|
activities = data['activities'] || {}
|
86
|
+
badge_links = data['badgelinks'] || {}
|
82
87
|
|
83
88
|
items.each do |item|
|
84
89
|
attributes = {}
|
@@ -93,7 +98,7 @@ module Osm
|
|
93
98
|
attributes[:start_time] = item['starttime'].nil? ? nil : item['starttime'][0..4]
|
94
99
|
attributes[:finish_time] = item['endtime'].nil? ? nil : item['endtime'][0..4]
|
95
100
|
attributes[:date] = Osm::parse_date(item['meetingdate'])
|
96
|
-
|
101
|
+
|
97
102
|
our_activities = activities[item['eveningid']]
|
98
103
|
attributes[:activities] = Array.new
|
99
104
|
unless our_activities.nil?
|
@@ -105,7 +110,21 @@ module Osm
|
|
105
110
|
)
|
106
111
|
end
|
107
112
|
end
|
108
|
-
|
113
|
+
|
114
|
+
our_badge_links = badge_links[item['eveningid']]
|
115
|
+
attributes[:badge_links] = Array.new
|
116
|
+
unless our_badge_links.nil?
|
117
|
+
our_badge_links.each do |badge_link_data|
|
118
|
+
attributes[:badge_links].push Osm::Meeting::BadgeLink.new(
|
119
|
+
:badge_key => badge_link_data['badge'],
|
120
|
+
:badge_type => badge_link_data['badgetype'].downcase.to_sym,
|
121
|
+
:requirement_key => badge_link_data['columnname'],
|
122
|
+
:badge_section => badge_link_data['section'].downcase.to_sym,
|
123
|
+
:label => badge_link_data['label'],
|
124
|
+
)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
109
128
|
result.push new(attributes)
|
110
129
|
end
|
111
130
|
|
@@ -156,7 +175,17 @@ module Osm
|
|
156
175
|
}
|
157
176
|
activities_data.push this_activity
|
158
177
|
end
|
159
|
-
|
178
|
+
|
179
|
+
badge_links_data = Array.new
|
180
|
+
badge_links.each do |badge_link|
|
181
|
+
this_badge_link = {
|
182
|
+
'section' => badge_link.badge_section,
|
183
|
+
'badge' => badge_link.badge_key,
|
184
|
+
'columnname' => badge_link.requirement_key,
|
185
|
+
'badgetype' => badge_link.badge_type,
|
186
|
+
}
|
187
|
+
badge_links_data.push this_badge_link
|
188
|
+
end
|
160
189
|
|
161
190
|
api_data = {
|
162
191
|
'eveningid' => id,
|
@@ -170,7 +199,8 @@ module Osm
|
|
170
199
|
'postnotes' => post_notes,
|
171
200
|
'games' => games,
|
172
201
|
'leaders' => leaders,
|
173
|
-
'activity' => activities_data,
|
202
|
+
'activity' => ActiveSupport::JSON.encode(activities_data),
|
203
|
+
'badgelinks' => ActiveSupport::JSON.encode(badge_links_data),
|
174
204
|
}
|
175
205
|
response = api.perform_query("programme.php?action=editEvening", api_data)
|
176
206
|
|
@@ -290,6 +320,46 @@ module Osm
|
|
290
320
|
|
291
321
|
end # Class Meeting::Activity
|
292
322
|
|
323
|
+
|
324
|
+
class BadgeLink
|
325
|
+
include ActiveModel::MassAssignmentSecurity
|
326
|
+
include ActiveAttr::Model
|
327
|
+
|
328
|
+
# @!attribute [rw] badge_key
|
329
|
+
# @return [String] the badge being done
|
330
|
+
# @!attribute [rw] badge_type
|
331
|
+
# @return [Symbol] the type of badge
|
332
|
+
# @!attribute [rw] requirement_key
|
333
|
+
# @return [String] the requirement being done
|
334
|
+
# @!attribute [rw] badge_section
|
335
|
+
# @return [Symbol] the section type that the badge belongs to
|
336
|
+
# @!attribute [rw] label
|
337
|
+
# @return [String] human firendly label for the badge and requirement
|
338
|
+
|
339
|
+
attribute :badge_key, :type => String
|
340
|
+
attribute :badge_type, :type => Object
|
341
|
+
attribute :requirement_key, :type => String
|
342
|
+
attribute :badge_section, :type => Object
|
343
|
+
attribute :label, :type => String
|
344
|
+
|
345
|
+
attr_accessible :badge_key, :badge_type, :requirement_key, :badge_section, :label
|
346
|
+
|
347
|
+
validates_presence_of :badge_key
|
348
|
+
validates_format_of :requirement_key, :with => /\A[a-z]_\d{2}\Z/, :message => 'is not in the correct format (e.g. "a_01")'
|
349
|
+
validates_inclusion_of :badge_section, :in => [:beavers, :cubs, :scouts, :explorers]
|
350
|
+
validates_inclusion_of :badge_type, :in => [:core, :staged, :activity, :challenge]
|
351
|
+
|
352
|
+
# @!method initialize
|
353
|
+
# Initialize a new Meeting::Activity
|
354
|
+
# @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
355
|
+
|
356
|
+
# Compare BadgeLink based on title then activity_id
|
357
|
+
def <=>(another)
|
358
|
+
return self.label <=> another.try(:label)
|
359
|
+
end
|
360
|
+
|
361
|
+
end # Class Meeting::BadgeLink
|
362
|
+
|
293
363
|
end # Class Meeting
|
294
364
|
|
295
365
|
end # Module
|
data/spec/osm/event_spec.rb
CHANGED
@@ -155,7 +155,7 @@ describe "Event" do
|
|
155
155
|
'notes' => 'Notes',
|
156
156
|
'notepad' => 'notepad',
|
157
157
|
'publicnotes' => 'public notepad',
|
158
|
-
'config' => '[{"id":"f_1","name":"Name","pL":"Label"}]',
|
158
|
+
'config' => '[{"id":"f_1","name":"Name","pL":"Label","pR":"1"}]',
|
159
159
|
'sectionid' => '1',
|
160
160
|
'googlecalendar' => nil,
|
161
161
|
'archived' => '0',
|
@@ -200,6 +200,7 @@ describe "Event" do
|
|
200
200
|
event.columns[0].id.should == 'f_1'
|
201
201
|
event.columns[0].name.should == 'Name'
|
202
202
|
event.columns[0].label.should == 'Label'
|
203
|
+
event.columns[0].parent_required.should == true
|
203
204
|
event.valid?.should be_true
|
204
205
|
end
|
205
206
|
|
@@ -778,6 +779,7 @@ describe "Event" do
|
|
778
779
|
'secret' => 'secret',
|
779
780
|
'columnName' => 'Test name',
|
780
781
|
'parentLabel' => 'Test label',
|
782
|
+
'parentRequire' => 1
|
781
783
|
}
|
782
784
|
body = {
|
783
785
|
'eventid' => '2',
|
@@ -787,7 +789,7 @@ describe "Event" do
|
|
787
789
|
|
788
790
|
event = Osm::Event.new(:id => 2, :section_id => 1)
|
789
791
|
event.should_not be_nil
|
790
|
-
event.add_column(@api, 'Test name', 'Test label').should be_true
|
792
|
+
event.add_column(@api, 'Test name', 'Test label', true).should be_true
|
791
793
|
column = event.columns[0]
|
792
794
|
column.id.should == 'f_1'
|
793
795
|
column.name.should == 'Test name'
|
@@ -813,10 +815,11 @@ describe "Event" do
|
|
813
815
|
'columnId' => 'f_1',
|
814
816
|
'columnName' => 'New name',
|
815
817
|
'pL' => 'New label',
|
818
|
+
'pR' => 1
|
816
819
|
}
|
817
820
|
body = {
|
818
821
|
'eventid' => '2',
|
819
|
-
'config' => '[{"id":"f_1","name":"New name","pL":"New label"}]'
|
822
|
+
'config' => '[{"id":"f_1","name":"New name","pL":"New label","pR":"1"}]'
|
820
823
|
}
|
821
824
|
HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body.to_json}) }
|
822
825
|
|
@@ -825,6 +828,7 @@ describe "Event" do
|
|
825
828
|
column = event.columns[0]
|
826
829
|
column.name = 'New name'
|
827
830
|
column.label = 'New label'
|
831
|
+
column.parent_required = true
|
828
832
|
|
829
833
|
column.update(@api).should be_true
|
830
834
|
|
@@ -873,6 +877,41 @@ describe "Event" do
|
|
873
877
|
column.delete(@api).should be_false
|
874
878
|
end
|
875
879
|
|
880
|
+
it "Get audit trail" do
|
881
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=getEventAudit§ionid=1&scoutid=2&eventid=3'
|
882
|
+
post_data = {
|
883
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
884
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
885
|
+
'userid' => 'user_id',
|
886
|
+
'secret' => 'secret',
|
887
|
+
}
|
888
|
+
data = [
|
889
|
+
{"date" => "10/06/2013 19:17","updatedby" => "My.SCOUT","type" => "detail","desc" => "Set 'Test' to 'Test data'"},
|
890
|
+
{"date" => "10/06/2013 19:16","updatedby" => "My.SCOUT","type" => "attendance","desc" => "Attendance: Yes"},
|
891
|
+
{"date" => "10/06/2013 19:15","updatedby" => "A Leader ","type" => "attendance","desc" => "Attendance: Reserved"},
|
892
|
+
{"date" => "10/06/2013 19:14","updatedby" => "A Leader ","type" => "attendance","desc" => "Attendance: No"},
|
893
|
+
{"date" => "10/06/2013 19:13","updatedby" => "A Leader ","type" => "attendance","desc" => "Attendance: Yes"},
|
894
|
+
{"date" => "10/06/2013 19:12","updatedby" => "A Leader ","type" => "attendance","desc" => "Attendance: Invited"},
|
895
|
+
{"date" => "10/06/2013 19:11","updatedby" => "A Leader ","type" => "attendance","desc" => "Attendance: Show in My.SCOUT"},
|
896
|
+
]
|
897
|
+
|
898
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>data.to_json}) }
|
899
|
+
|
900
|
+
ea = Osm::Event::Attendance.new(
|
901
|
+
:event => Osm::Event.new(:id => 3, :section_id => 1),
|
902
|
+
:member_id => 2,
|
903
|
+
)
|
904
|
+
ea.get_audit_trail(@api).should == [
|
905
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 17), :by => 'My.SCOUT', :type => :detail, :description => "Set 'Test' to 'Test data'", :label => 'Test', :value => 'Test data'},
|
906
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 16), :by => 'My.SCOUT', :type => :attendance, :description => "Attendance: Yes", :attendance => :yes},
|
907
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 15), :by => 'A Leader', :type => :attendance, :description => "Attendance: Reserved", :attendance => :reserved},
|
908
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 14), :by => 'A Leader', :type => :attendance, :description => "Attendance: No", :attendance => :no},
|
909
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 13), :by => 'A Leader', :type => :attendance, :description => "Attendance: Yes", :attendance => :yes},
|
910
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 12), :by => 'A Leader', :type => :attendance, :description => "Attendance: Invited", :attendance => :invited},
|
911
|
+
{:event_attendance => ea, :event_id => 3, :member_id => 2, :at => DateTime.new(2013, 6, 10, 19, 11), :by => 'A Leader', :type => :attendance, :description => "Attendance: Show in My.SCOUT", :attendance => :shown},
|
912
|
+
]
|
913
|
+
end
|
914
|
+
|
876
915
|
end
|
877
916
|
|
878
917
|
|
data/spec/osm/meeting_spec.rb
CHANGED
@@ -17,7 +17,8 @@ describe "Meeting" do
|
|
17
17
|
:start_time => '19:00',
|
18
18
|
:finish_time => '21:00',
|
19
19
|
:date => Date.new(2000, 01, 02),
|
20
|
-
:activities => []
|
20
|
+
:activities => [],
|
21
|
+
:badge_links => []
|
21
22
|
)
|
22
23
|
|
23
24
|
e.id.should == 1
|
@@ -32,6 +33,7 @@ describe "Meeting" do
|
|
32
33
|
e.finish_time.should == '21:00'
|
33
34
|
e.date.should == Date.new(2000, 1, 2)
|
34
35
|
e.activities.should == []
|
36
|
+
e.badge_links.should == []
|
35
37
|
e.valid?.should be_true
|
36
38
|
end
|
37
39
|
|
@@ -49,7 +51,7 @@ describe "Meeting" do
|
|
49
51
|
|
50
52
|
describe "Meeting::Activity" do
|
51
53
|
|
52
|
-
it "Create
|
54
|
+
it "Create" do
|
53
55
|
ea = Osm::Meeting::Activity.new(
|
54
56
|
:activity_id => 2,
|
55
57
|
:title => 'Activity Name',
|
@@ -74,21 +76,84 @@ describe "Meeting" do
|
|
74
76
|
end
|
75
77
|
|
76
78
|
|
79
|
+
describe "Meeting::BadgeLink" do
|
80
|
+
|
81
|
+
it "Create" do
|
82
|
+
bl = Osm::Meeting::BadgeLink.new(
|
83
|
+
:badge_key => 'artist',
|
84
|
+
:badge_type => :activity,
|
85
|
+
:requirement_key => 'a_01',
|
86
|
+
:badge_section => :cubs,
|
87
|
+
:label => 'Cubs Artist Activity - A: Poster',
|
88
|
+
)
|
89
|
+
|
90
|
+
bl.badge_key.should == 'artist'
|
91
|
+
bl.badge_type.should == :activity
|
92
|
+
bl.requirement_key.should == 'a_01'
|
93
|
+
bl.badge_section.should == :cubs
|
94
|
+
bl.label.should == 'Cubs Artist Activity - A: Poster'
|
95
|
+
bl.valid?.should be_true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "Sorts by label" do
|
99
|
+
a1 = Osm::Meeting::BadgeLink.new(:label => 'a')
|
100
|
+
a2 = Osm::Meeting::BadgeLink.new(:label => 'b')
|
101
|
+
|
102
|
+
data = [a2, a1]
|
103
|
+
data.sort.should == [a1, a2]
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
|
77
109
|
describe 'Using the API' do
|
78
110
|
|
79
111
|
it "Fetch the term's programme for a section" do
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
112
|
+
body = {
|
113
|
+
"items" => [{"eveningid" => "5", "sectionid" =>"3", "title" => "Weekly Meeting 1", "notesforparents" => "parents", "games" => "games", "prenotes" => "before", "postnotes" => "after", "leaders" => "leaders", "meetingdate" => "2001-02-03", "starttime" => "19:15:00", "endtime" => "20:30:00", "googlecalendar" => ""}],
|
114
|
+
"activities" => {"5" => [
|
115
|
+
{"activityid" => "6", "title" => "Activity 6", "notes" => "Some notes", "eveningid" => "5"},
|
116
|
+
{"activityid" => "7", "title" => "Activity 7", "notes" => "", "eveningid" => "5"}
|
117
|
+
]},
|
118
|
+
"badgelinks" => {"5" => [{
|
119
|
+
"badge" => "artist",
|
120
|
+
"badgetype" => "activity",
|
121
|
+
"columnname" => "a_01",
|
122
|
+
"eveningid" => "5",
|
123
|
+
"label" => "Cubs Artist Activity - A: Poster",
|
124
|
+
"section" => "cubs",
|
125
|
+
"sectionid" => "3",
|
126
|
+
}]},
|
127
|
+
}
|
86
128
|
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/programme.php?action=getProgramme§ionid=3&termid=4", :body => body.to_json)
|
87
129
|
|
88
130
|
programme = Osm::Meeting.get_for_section(@api, 3, 4)
|
89
131
|
programme.size.should == 1
|
90
|
-
programme[0]
|
91
|
-
|
132
|
+
meeting = programme[0]
|
133
|
+
meeting.is_a?(Osm::Meeting).should be_true
|
134
|
+
meeting.id.should == 5
|
135
|
+
meeting.section_id.should == 3
|
136
|
+
meeting.title.should == 'Weekly Meeting 1'
|
137
|
+
meeting.notes_for_parents.should == 'parents'
|
138
|
+
meeting.games.should == 'games'
|
139
|
+
meeting.pre_notes.should == 'before'
|
140
|
+
meeting.post_notes.should == 'after'
|
141
|
+
meeting.leaders.should == 'leaders'
|
142
|
+
meeting.date.should == Date.new(2001, 2, 3)
|
143
|
+
meeting.start_time.should == '19:15'
|
144
|
+
meeting.finish_time.should == '20:30'
|
145
|
+
meeting.activities.size.should == 2
|
146
|
+
activity = meeting.activities[0]
|
147
|
+
activity.activity_id.should == 6
|
148
|
+
activity.title.should == 'Activity 6'
|
149
|
+
activity.notes.should == 'Some notes'
|
150
|
+
meeting.badge_links.size.should == 1
|
151
|
+
badge_link = meeting.badge_links[0]
|
152
|
+
badge_link.badge_key.should == 'artist'
|
153
|
+
badge_link.badge_type.should == :activity
|
154
|
+
badge_link.requirement_key.should == 'a_01'
|
155
|
+
badge_link.badge_section.should == :cubs
|
156
|
+
badge_link.label.should == 'Cubs Artist Activity - A: Poster'
|
92
157
|
end
|
93
158
|
|
94
159
|
it "Fetch badge requirements for a meeting" do
|
@@ -181,12 +246,20 @@ describe "Meeting" do
|
|
181
246
|
'secret' => 'secret',
|
182
247
|
'eveningid' => 1, 'sectionid' => 2, 'meetingdate' => '2000-01-02', 'starttime' => nil,
|
183
248
|
'endtime' => nil, 'title' => 'Unnamed meeting', 'notesforparents' =>'', 'prenotes' => '',
|
184
|
-
'postnotes' => '', 'games' => '', 'leaders' => '',
|
249
|
+
'postnotes' => '', 'games' => '', 'leaders' => '',
|
250
|
+
'activity' => '[{"activityid":3,"notes":"Some notes"}]',
|
251
|
+
'badgelinks' => '[{"section":"beavers","badge":"badge","columnname":"b_03","badgetype":"activity"}]',
|
185
252
|
}
|
186
253
|
Osm::Term.stub(:get_for_section) { [] }
|
187
254
|
HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
|
188
255
|
|
189
|
-
meeting = Osm::Meeting.new(
|
256
|
+
meeting = Osm::Meeting.new(
|
257
|
+
:id=>1,
|
258
|
+
:section_id=>2,
|
259
|
+
:date=>Date.new(2000, 01, 02),
|
260
|
+
:activities => [Osm::Meeting::Activity.new(:activity_id => 3, :title => 'Activity Title', :notes => 'Some notes')],
|
261
|
+
:badge_links => [Osm::Meeting::BadgeLink.new(:badge_key => 'badge', :badge_type => :activity, :requirement_key => 'b_03', :badge_section => :beavers, :label => 'Label')]
|
262
|
+
)
|
190
263
|
meeting.update(@api).should be_true
|
191
264
|
end
|
192
265
|
|
@@ -199,7 +272,7 @@ describe "Meeting" do
|
|
199
272
|
'secret' => 'secret',
|
200
273
|
'eveningid' => 1, 'sectionid' => 2, 'meetingdate' => '2000-01-02', 'starttime' => nil,
|
201
274
|
'endtime' => nil, 'title' => 'Unnamed meeting', 'notesforparents' =>'', 'prenotes' => '',
|
202
|
-
'postnotes' => '', 'games' => '', 'leaders' => '', 'activity' => '[]',
|
275
|
+
'postnotes' => '', 'games' => '', 'leaders' => '', 'activity' => '[]', 'badgelinks' => '[]',
|
203
276
|
}
|
204
277
|
Osm::Term.stub(:get_for_section) { [] }
|
205
278
|
HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|