osm 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
5
6
  branches:
6
7
  only:
7
8
  - master
data/CHANGELOG.md CHANGED
@@ -1,6 +1,26 @@
1
+ ## Version 0.5.0
2
+
3
+ * Code breaking changes to DueBadges:
4
+ * The by\_member attribute now uses scout\_id as the key
5
+ * Addition of member\_names attribute to allow fetching of members names (the old key for the by\_member attribute)
6
+ * descriptions attribute has been renamed to badge\_names for consistency
7
+ * Code breaking changes to Register and subclasses:
8
+ * Register:
9
+ * update\_attendance - :attendance option is now a Symbol not String (:yes, :unadvised\_absent or :advised\_absent)
10
+ * Register::Attendance:
11
+ * attendance attribute is now a Hash of Date to Symbol (instead of to String)
12
+ * Register::Attendance gains two helper methods:
13
+ * present\_on?(date)
14
+ * absent\_on?(date)
15
+ * Add allow\_booking attribute to Event
16
+ * Add myscout\_programme\_times attribute to Section
17
+ * Cost attribute of Event is now checked to be either "TBC" or formatted to /\\A\\d+\\.\\d{2}\\Z/
18
+ * Add cost\_tbc? method to Event
19
+ * Add cost\_free? method to Event
20
+
1
21
  ## Version 0.4.2
2
22
 
3
- * Fix undefined variable "section_id" when fetching notepad from cache
23
+ * Fix undefined variable "section\_id" when fetching notepad from cache
4
24
 
5
25
  ## Version 0.4.1
6
26
 
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  ##Build State
6
- This project uses continuous integration to help ensure that a quality product is delivered. It is tested using ruby 1.9.2 and 1.9.3 other versions may work but are not guarenteed (since they aren't tested).
6
+ This project uses continuous integration to help ensure that a quality product is delivered.
7
7
  Travis CI monitors two branches (versions) of the code - Master (which is what gets released)
8
8
  and Staging (which is what is currently being debugged ready for moving to master).
9
9
 
@@ -12,6 +12,14 @@ Master [![Build Status](https://secure.travis-ci.org/robertgauld/osm.png?branch=
12
12
  Staging [![Build Status](https://secure.travis-ci.org/robertgauld/osm.png?branch=staging)](http://travis-ci.org/robertgauld/osm)
13
13
 
14
14
 
15
+ ## Ruby Versions
16
+ This gem supports the following versions of ruby, it may work on other versions but is not tested against them so don't rely on it.
17
+
18
+ * 1.9.2
19
+ * 1.9.3
20
+ * 2.0.0
21
+
22
+
15
23
  ## OSM
16
24
 
17
25
  Use the [Online Scout Manager](https://www.onlinescoutmanager.co.uk) API.
@@ -24,7 +32,7 @@ Use the [Online Scout Manager](https://www.onlinescoutmanager.co.uk) API.
24
32
  Add to your Gemfile and run the `bundle` command to install it.
25
33
 
26
34
  ```ruby
27
- gem 'osm', '~> 0.3.0'
35
+ gem 'osm', '~> 0.5.0'
28
36
  ```
29
37
 
30
38
  Configure the gem during the initalization of the app (e.g. if using rails then config/initializers/osm.rb would look like):
data/lib/osm/badges.rb CHANGED
@@ -69,57 +69,66 @@ module Osm
69
69
  pending_raw = data['pending'] || {}
70
70
  descriptions_raw = data['description'] || {}
71
71
 
72
- attributes = {
73
- :by_member => {},
74
- :descriptions => {}
75
- }
76
-
72
+ by_member = {}
73
+ member_names = {}
74
+ badge_names = {}
77
75
  pending_raw.each do |key, members|
78
76
  members.each do |member|
79
- name = "#{member['firstname']} #{member['lastname']}"
77
+ id = Osm.to_i_or_nil(member['scoutid'])
80
78
  description = descriptions_raw[key]['name'] + (descriptions_raw[key]['section'].eql?('staged') ? " (Level #{member['level']})" : '')
81
79
  description_key = key + (descriptions_raw[key]['section'].eql?('staged') ? "_#{member['level']}" : '_1')
82
- attributes[:descriptions][description_key] = description
83
- attributes[:by_member][name] ||= []
84
- attributes[:by_member][name].push(description_key)
80
+ badge_names[description_key] = description
81
+ by_member[id] ||= []
82
+ by_member[id].push(description_key)
83
+ member_names[id] = "#{member['firstname']} #{member['lastname']}"
85
84
  end
86
85
  end
87
86
 
88
- due_badges = Osm::Badges::DueBadges.new(attributes)
87
+ due_badges = Osm::Badges::DueBadges.new(
88
+ :by_member => by_member,
89
+ :member_names => member_names,
90
+ :badge_names => badge_names,
91
+ )
89
92
  Osm::Model.cache_write(api, cache_key, due_badges)
90
93
  return due_badges
91
94
  end
92
95
 
93
96
 
94
97
  class DueBadges < Osm::Model
95
- # @!attribute [rw] descriptions
96
- # @return [Hash] descriptions for each of the badges
98
+ # @!attribute [rw] badge_names
99
+ # @return [Hash] name to display for each of the badges
97
100
  # @!attribute [rw] by_member
98
101
  # @return [Hash] the due badges grouped by member
102
+ # @!attribute [rw] member_names
103
+ # @return [Hash] the name to display for each member
99
104
 
100
- attribute :descriptions, :default => {}
105
+ attribute :badge_names, :default => {}
101
106
  attribute :by_member, :default => {}
107
+ attribute :member_names, :default => {}
102
108
 
103
- attr_accessible :descriptions, :by_member
109
+ attr_accessible :badge_names, :by_member, :member_names
104
110
 
105
- validates :descriptions, :hash => {:key_type => String, :value_type => String}
111
+ validates :badge_names, :hash => {:key_type => String, :value_type => String}
112
+ validates :member_names, :hash => {:key_type => Fixnum, :value_type => String}
106
113
 
107
114
  validates_each :by_member do |record, attr, value|
108
- desc_keys = record.descriptions.keys
115
+ badge_names_keys = record.badge_names.keys
116
+ member_names_keys = record.member_names.keys
109
117
  record.errors.add(attr, 'must be a Hash') unless value.is_a?(Hash)
110
118
  value.each do |k, v|
111
- record.errors.add(attr, 'keys must be String') unless k.is_a?(String)
119
+ record.errors.add(attr, 'keys must be Fixnum') unless k.is_a?(Fixnum)
120
+ record.errors.add(attr, 'keys must exist as a key in :member_names') unless member_names_keys.include?(k)
112
121
  record.errors.add(attr, 'values must be Arrays') unless v.is_a?(Array)
113
122
  v.each do |vv|
114
123
  record.errors.add(attr, 'internal values must be Strings') unless vv.is_a?(String)
115
- record.errors.add(attr, 'internal values must exist as a key in :descriptions') unless desc_keys.include?(vv)
124
+ record.errors.add(attr, 'internal values must exist as a key in :badge_names') unless badge_names_keys.include?(vv)
116
125
  end
117
126
  end
118
127
  end
119
128
 
120
129
 
121
130
  # @!method initialize
122
- # Initialize a new Term
131
+ # Initialize a new DueBadges
123
132
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
124
133
 
125
134
 
@@ -133,8 +142,8 @@ module Osm
133
142
  # @return [Hash] the total number of each badge which is due
134
143
  def totals()
135
144
  totals = {}
136
- by_member.keys.each do |member_name|
137
- by_member[member_name].each do |badge|
145
+ by_member.each do |member_name, badges|
146
+ badges.each do |badge|
138
147
  totals[badge] ||= 0
139
148
  totals[badge] += 1
140
149
  end
data/lib/osm/event.rb CHANGED
@@ -14,7 +14,7 @@ module Osm
14
14
  # @!attribute [rw] finish
15
15
  # @return [DateTime] when the event ends
16
16
  # @!attribute [rw] cost
17
- # @return [String] the cost of the event
17
+ # @return [String] the cost of the event (formatted to \d+\.\d{2}) or "TBC"
18
18
  # @!attribute [rw] location
19
19
  # @return [String] where the event is
20
20
  # @!attribute [rw] notes
@@ -37,13 +37,15 @@ module Osm
37
37
  # @return [Fixnum] the maximum number of people who can attend the event (0 = no limit)
38
38
  # @!attendance [rw] attendance_limit_includes_leaders
39
39
  # @return [Boolean] whether the attendance limit includes leaders
40
+ # @!attribute [rw] allow_booking
41
+ # @return [Boolean] whether booking is allowed through My.SCOUT
40
42
 
41
43
  attribute :id, :type => Integer
42
44
  attribute :section_id, :type => Integer
43
45
  attribute :name, :type => String
44
46
  attribute :start, :type => DateTime
45
47
  attribute :finish, :type => DateTime
46
- attribute :cost, :type => String, :default => ''
48
+ attribute :cost, :type => String, :default => 'TBC'
47
49
  attribute :location, :type => String, :default => ''
48
50
  attribute :notes, :type => String, :default => ''
49
51
  attribute :archived, :type => Boolean, :default => false
@@ -55,10 +57,11 @@ module Osm
55
57
  attribute :reminders, :type => Boolean, :default => true
56
58
  attribute :attendance_limit, :type => Integer, :default => 0
57
59
  attribute :attendance_limit_includes_leaders, :type => Boolean, :default => false
60
+ attribute :allow_booking, :type => Boolean, :default => true
58
61
 
59
62
  attr_accessible :id, :section_id, :name, :start, :finish, :cost, :location, :notes, :archived,
60
63
  :fields, :columns, :notepad, :public_notepad, :confirm_by_date, :allow_changes,
61
- :reminders, :attendance_limit, :attendance_limit_includes_leaders
64
+ :reminders, :attendance_limit, :attendance_limit_includes_leaders, :allow_booking
62
65
 
63
66
  validates_numericality_of :id, :only_integer=>true, :greater_than=>0, :allow_nil => true
64
67
  validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
@@ -68,6 +71,8 @@ module Osm
68
71
  validates_inclusion_of :allow_changes, :in => [true, false]
69
72
  validates_inclusion_of :reminders, :in => [true, false]
70
73
  validates_inclusion_of :attendance_limit_includes_leaders, :in => [true, false]
74
+ validates_inclusion_of :allow_booking, :in => [true, false]
75
+ validates_format_of :cost, :with => /\A(?:\d+\.\d{2}|TBC)\Z/
71
76
 
72
77
 
73
78
  # @!method initialize
@@ -149,7 +154,7 @@ module Osm
149
154
  'location' => event.location,
150
155
  'startdate' => event.start? ? event.start.strftime(Osm::OSM_DATE_FORMAT) : '',
151
156
  'enddate' => event.finish? ? event.finish.strftime(Osm::OSM_DATE_FORMAT) : '',
152
- 'cost' => event.cost,
157
+ 'cost' => event.cost_tbc? ? '-1' : event.cost,
153
158
  'notes' => event.notes,
154
159
  'starttime' => event.start? ? event.start.strftime(Osm::OSM_TIME_FORMAT) : '',
155
160
  'endtime' => event.finish? ? event.finish.strftime(Osm::OSM_TIME_FORMAT) : '',
@@ -157,7 +162,8 @@ module Osm
157
162
  'allowChanges' => event.allow_changes ? 'true' : 'false',
158
163
  'disablereminders' => !event.reminders ? 'true' : 'false',
159
164
  'attendancelimit' => event.attendance_limit,
160
- 'limitincludesleaders' => event.attendance_limit_includes_leaders,
165
+ 'limitincludesleaders' => event.attendance_limit_includes_leaders ? 'true' : 'false',
166
+ 'allowbooking' => event.allow_booking ? 'true' : 'false',
161
167
  })
162
168
 
163
169
  # The cached events for the section will be out of date - remove them
@@ -186,7 +192,7 @@ module Osm
186
192
  'location' => location,
187
193
  'startdate' => start? ? start.strftime(Osm::OSM_DATE_FORMAT) : '',
188
194
  'enddate' => finish? ? finish.strftime(Osm::OSM_DATE_FORMAT) : '',
189
- 'cost' => cost,
195
+ 'cost' => cost_tbc? ? '-1' : cost,
190
196
  'notes' => notes,
191
197
  'starttime' => start? ? start.strftime(Osm::OSM_TIME_FORMAT) : '',
192
198
  'endtime' => finish? ? finish.strftime(Osm::OSM_TIME_FORMAT) : '',
@@ -194,7 +200,8 @@ module Osm
194
200
  'allowChanges' => allow_changes ? 'true' : 'false',
195
201
  'disablereminders' => !reminders ? 'true' : 'false',
196
202
  'attendancelimit' => attendance_limit,
197
- 'limitincludesleaders' => attendance_limit_includes_leaders,
203
+ 'limitincludesleaders' => attendance_limit_includes_leaders ? 'true' : 'false',
204
+ 'allowbooking' => allow_booking ? 'true' : 'false',
198
205
  })
199
206
 
200
207
  api.perform_query("events.php?action=saveNotepad&sectionid=#{section_id}", {
@@ -333,6 +340,18 @@ module Osm
333
340
  return attendance_limit - attendees(api)
334
341
  end
335
342
 
343
+ # Whether the cost is to be confirmed
344
+ # @return [Boolean] whether the cost is TBC
345
+ def cost_tbc?
346
+ cost.eql?('TBC')
347
+ end
348
+
349
+ # Whether the cost is zero
350
+ # @return [Boolean] whether the cost is zero
351
+ def cost_free?
352
+ cost.eql?('0.00')
353
+ end
354
+
336
355
  # Compare Event based on start, name then id
337
356
  def <=>(another)
338
357
  return 0 if self.id == another.try(:id)
@@ -359,7 +378,7 @@ module Osm
359
378
  :name => event_data['name'],
360
379
  :start => Osm::make_datetime(event_data['startdate'], event_data['starttime']),
361
380
  :finish => Osm::make_datetime(event_data['enddate'], event_data['endtime']),
362
- :cost => event_data['cost'],
381
+ :cost => event_data['cost'].eql?('-1') ? 'TBC' : event_data['cost'],
363
382
  :location => event_data['location'],
364
383
  :notes => event_data['notes'],
365
384
  :archived => event_data['archived'].eql?('1'),
@@ -370,6 +389,7 @@ module Osm
370
389
  :reminders => !event_data['disablereminders'].eql?('1'),
371
390
  :attendance_limit => event_data['attendancelimit'].to_i,
372
391
  :attendance_limit_includes_leaders => event_data['limitincludesleaders'].eql?('1'),
392
+ :allow_booking => event_data['allowbooking'].eql?('1'),
373
393
  )
374
394
 
375
395
  columns = []
data/lib/osm/register.rb CHANGED
@@ -56,6 +56,7 @@ module Osm
56
56
  end
57
57
 
58
58
  data = api.perform_query("users.php?action=register&sectionid=#{section_id}&termid=#{term_id}")
59
+ dates = get_structure(api, section, term, options).map{ |f| f.id }.select{ |f| f.match(Osm::OSM_DATE_REGEX) }
59
60
 
60
61
  to_return = []
61
62
  if data.is_a?(Hash) && data['items'].is_a?(Array)
@@ -63,6 +64,15 @@ module Osm
63
64
  data.each do |item|
64
65
  if item.is_a?(Hash)
65
66
  unless item['scoutid'].to_i < 0 # It's a total row
67
+ attendance = {}
68
+ dates.each do |date|
69
+ item_attendance = item[date]
70
+ date = Date.strptime(date, Osm::OSM_DATE_FORMAT)
71
+ attendance[date] = :unadvised_absent
72
+ attendance[date] = :yes if item_attendance.eql?('Yes')
73
+ attendance[date] = :advised_absent if item_attendance.eql?('No')
74
+ end
75
+ item.select{}
66
76
  to_return.push Osm::Register::Attendance.new(
67
77
  :member_id => Osm::to_i_or_nil(item['scoutid']),
68
78
  :grouping_id => Osm::to_i_or_nil(item ['patrolid']),
@@ -70,8 +80,7 @@ module Osm
70
80
  :first_name => item['firstname'],
71
81
  :last_name => item['lastname'],
72
82
  :total => item['total'].to_i,
73
- :attendance => item.select { |key, value| key.to_s.match(Osm::OSM_DATE_REGEX) }.
74
- inject({}){ |new_hash,(date, attendance)| new_hash[Date.strptime(date, Osm::OSM_DATE_FORMAT)] = attendance; new_hash },
83
+ :attendance => attendance,
75
84
  )
76
85
  end
77
86
  end
@@ -87,7 +96,7 @@ module Osm
87
96
  # @option data [Osm::Section] :section the section to update the register for
88
97
  # @option data [Osm::Term, #to_i, nil] :term The term (or its ID) to get the register for, passing nil causes the current term to be used
89
98
  # @option data [Osm::Evening, DateTime, Date] :evening the evening to update the register on
90
- # @option data [String] :attendance what to mark the attendance as, one of "Yes", "No" or "Absent"
99
+ # @option data [Symbol] :attendance what to mark the attendance as, one of :yes, :unadvised_absent or :advised_absent
91
100
  # @option data [Fixnum, Array<Fixnum>, Osm::Member, Array<Osm::Member>] :members the members (or their ids) to update
92
101
  # @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
93
102
  # @return [Boolean] whether the update succedded
@@ -97,7 +106,7 @@ module Osm
97
106
  # @raise [Osm::ArgumentIsInvalid] If data[:members] is missing
98
107
  # @raise [Osm::ArgumentIsInvalid] If data[:api] is missing
99
108
  def self.update_attendance(data={})
100
- raise Osm::ArgumentIsInvalid, ':attendance is invalid' unless ['Yes', 'No', 'Absent'].include?(data[:attendance])
109
+ raise Osm::ArgumentIsInvalid, ':attendance is invalid' unless [:yes, :unadvised_absent, :advised_absent].include?(data[:attendance])
101
110
  raise Osm::ArgumentIsInvalid, ':section is missing' if data[:section].nil?
102
111
  raise Osm::ArgumentIsInvalid, ':evening is missing' if data[:evening].nil?
103
112
  raise Osm::ArgumentIsInvalid, ':members is missing' if data[:members].nil?
@@ -112,7 +121,7 @@ module Osm
112
121
  response = api.perform_query("users.php?action=registerUpdate&sectionid=#{data[:section].id}&termid=#{term_id}", {
113
122
  'scouts' => data[:members].inspect,
114
123
  'selectedDate' => data[:evening].strftime(Osm::OSM_DATE_FORMAT),
115
- 'present' => data[:attendance],
124
+ 'present' => {:yes => 'Yes', :unadvised_absent => nil, :advised_absent => 'No'}[data[:attendance]],
116
125
  'section' => data[:section].type,
117
126
  'sectionid' => data[:section].id,
118
127
  'completedBadges' => (data[:completed_badge_requirements] || []).to_json
@@ -171,7 +180,7 @@ module Osm
171
180
  # @!attribute [rw] total
172
181
  # @return [FixNum] Total
173
182
  # @!attribute [rw] attendance
174
- # @return [Hash] The data for each field - keys are the date, values one of 'Yes' (present), 'No' (known absence) or nil (absent)
183
+ # @return [Hash] The data for each field - keys are the date, values one of :yes, :unadvised_absent or :advised_absent
175
184
 
176
185
  attribute :member_id, :type => Integer
177
186
  attribute :grouping_id, :type => Integer
@@ -190,7 +199,7 @@ module Osm
190
199
  validates_presence_of :first_name
191
200
  validates_presence_of :last_name
192
201
 
193
- validates :attendance, :hash => {:key_type => Date, :value_in => ['Yes', 'No', nil]}
202
+ validates :attendance, :hash => {:key_type => Date, :value_in => [:yes, :unadvised_absent, :advised_absent]}
194
203
 
195
204
 
196
205
  # @!method initialize
@@ -198,6 +207,21 @@ module Osm
198
207
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
199
208
 
200
209
 
210
+ # Find out if the member was present on a date
211
+ # @param [Date] date The date to check attendance for
212
+ # @return [Boolean] whether the member was presnt on the given date
213
+ def present_on?(date)
214
+ attendance[date] == :yes
215
+ end
216
+
217
+ # Find out if the member was absent on a date
218
+ # @param [Date] date The date to check attendance for
219
+ # @return [Boolean] whether the member was absent on the given date
220
+ def absent_on?(date)
221
+ attendance[date] != :yes
222
+ end
223
+
224
+
201
225
  # Compare Attendance based on section_id, grouping_id, last_name then first_name
202
226
  def <=>(another)
203
227
  result = self.section_id <=> another.try(:section_id)
data/lib/osm/section.rb CHANGED
@@ -51,6 +51,8 @@ module Osm
51
51
  # @return [Boolean] Wether parents can see partially completed badges
52
52
  # @!attribute [rw] myscout_programme_summary
53
53
  # @return [Boolean] Wether parents can see summary of programme items
54
+ # @!attribute [rw] myscout_programme_times
55
+ # @return [Boolean] Wether parents can see times of programme items
54
56
  # @!attribute [rw] myscout_event_reminder_count
55
57
  # @return [Fixnum] How many event reminders to send to parents who haven't responded
56
58
  # @!attribute [rw] myscout_event_reminder_frequency
@@ -85,6 +87,7 @@ module Osm
85
87
  attribute :myscout_email_address_copy, :type => String, :default => ''
86
88
  attribute :myscout_badges_partial, :type => Boolean
87
89
  attribute :myscout_programme_summary, :type => Boolean
90
+ attribute :myscout_programme_times, :type => Boolean
88
91
  attribute :myscout_event_reminder_count, :type => Integer
89
92
  attribute :myscout_event_reminder_frequency, :type => Integer
90
93
  attribute :myscout_payment_reminder_count, :type => Integer
@@ -96,7 +99,7 @@ module Osm
96
99
  :myscout_programme_expires, :myscout_events, :myscout_badges,
97
100
  :myscout_programme, :myscout_payments, :myscout_emails,
98
101
  :myscout_email_address_from, :myscout_email_address_copy,
99
- :myscout_badges_partial, :myscout_programme_summary,
102
+ :myscout_badges_partial, :myscout_programme_summary, :myscout_programme_times,
100
103
  :myscout_event_reminder_count, :myscout_event_reminder_frequency,
101
104
  :myscout_payment_reminder_count, :myscout_payment_reminder_frequency
102
105
 
@@ -126,6 +129,7 @@ module Osm
126
129
  validates_inclusion_of :myscout_payments, :in => [true, false]
127
130
  validates_inclusion_of :myscout_badges_partial, :in => [true, false]
128
131
  validates_inclusion_of :myscout_programme_summary, :in => [true, false]
132
+ validates_inclusion_of :myscout_programme_times, :in => [true, false]
129
133
 
130
134
  validates :column_names, :hash => {:key_type => Symbol, :value_type => String}
131
135
  validates :fields, :hash => {:key_type => Symbol, :value_in => [true, false]}
@@ -207,6 +211,7 @@ module Osm
207
211
  :myscout_email_address_copy => myscout_data['emailAddressCopy'] ? myscout_data['emailAddressCopy'] : '',
208
212
  :myscout_badges_partial => myscout_data['badgesPartial'] == 1,
209
213
  :myscout_programme_summary => myscout_data['programmeSummary'] == 1,
214
+ :myscout_programme_times => myscout_data['programmeTimes'] == 1,
210
215
  :myscout_event_reminder_count => myscout_data['eventRemindCount'].to_i,
211
216
  :myscout_event_reminder_frequency => myscout_data['eventRemindFrequency'].to_i,
212
217
  :myscout_payment_reminder_count => myscout_data['paymentRemindCount'].to_i,
@@ -19,13 +19,13 @@ describe "Badges" do
19
19
  }
20
20
  ],
21
21
  'staged_staged_participation' => [{
22
- 'sid' => '2',
22
+ 'scoutid' => '2',
23
23
  'firstname' => 'Jane',
24
24
  'lastname' => 'Doe',
25
25
  'level' => '2',
26
26
  'extra' => 'Lvl 2'
27
27
  }, {
28
- 'sid' => '1',
28
+ 'scoutid' => '1',
29
29
  'firstname' => 'John',
30
30
  'lastname' => 'Doe',
31
31
  'level' => '2',
@@ -33,7 +33,6 @@ describe "Badges" do
33
33
  }
34
34
  ]
35
35
  },
36
-
37
36
  'description' => {
38
37
  'badge_name' => {
39
38
  'name' => 'Badge Name',
@@ -53,8 +52,9 @@ describe "Badges" do
53
52
 
54
53
  db = Osm::Badges.get_due_badges(@api, Osm::Section.new(:id => 1, :type => :cubs), 2)
55
54
  db.empty?.should == false
56
- db.descriptions.should == {'badge_name_1'=>'Badge Name', 'staged_staged_participation_2'=>'Participation (Level 2)'}
57
- db.by_member.should == {'John Doe'=>['badge_name_1', 'staged_staged_participation_2'], 'Jane Doe'=>['staged_staged_participation_2']}
55
+ db.badge_names.should == {'badge_name_1'=>'Badge Name', 'staged_staged_participation_2'=>'Participation (Level 2)'}
56
+ db.by_member.should == {1=>['badge_name_1', 'staged_staged_participation_2'], 2=>['staged_staged_participation_2']}
57
+ db.member_names.should == {1 => 'John Doe', 2 => 'Jane Doe'}
58
58
  db.totals.should == {'staged_staged_participation_2'=>2, 'badge_name_1'=>1}
59
59
  db.valid?.should be_true
60
60
  end
@@ -11,7 +11,7 @@ describe "Event" do
11
11
  :name => 'Event name',
12
12
  :start => DateTime.new(2001, 1, 2, 12 ,0 ,0),
13
13
  :finish => nil,
14
- :cost => 'Free',
14
+ :cost => '1.23',
15
15
  :location => 'Somewhere',
16
16
  :notes => 'None',
17
17
  :archived => '0',
@@ -23,6 +23,7 @@ describe "Event" do
23
23
  :reminders => false,
24
24
  :attendance_limit => 3,
25
25
  :attendance_limit_includes_leaders => true,
26
+ :allow_booking => false,
26
27
  }
27
28
  event = Osm::Event.new(data)
28
29
 
@@ -31,7 +32,7 @@ describe "Event" do
31
32
  event.name.should == 'Event name'
32
33
  event.start.should == DateTime.new(2001, 1, 2, 12, 0, 0)
33
34
  event.finish.should == nil
34
- event.cost.should == 'Free'
35
+ event.cost.should == '1.23'
35
36
  event.location.should == 'Somewhere'
36
37
  event.notes.should == 'None'
37
38
  event.archived.should be_false
@@ -43,14 +44,26 @@ describe "Event" do
43
44
  event.reminders.should == false
44
45
  event.attendance_limit.should == 3
45
46
  event.attendance_limit_includes_leaders.should == true
47
+ event.allow_booking.should be_false
46
48
  event.valid?.should be_true
47
49
  end
48
50
 
49
- it "Correctly tells if attendance is limited" do
51
+ it "Tells if attendance is limited" do
50
52
  Osm::Event.new(:attendance_limit => 0).limited_attendance?.should be_false
51
53
  Osm::Event.new(:attendance_limit => 1).limited_attendance?.should be_true
52
54
  end
53
55
 
56
+ it "Tells if the cost is TBC" do
57
+ Osm::Event.new(:cost => 'TBC').cost_tbc?.should be_true
58
+ Osm::Event.new(:cost => '1.23').cost_tbc?.should be_false
59
+ end
60
+
61
+ it "Tells if the cost is free" do
62
+ Osm::Event.new(:cost => 'TBC').cost_free?.should be_false
63
+ Osm::Event.new(:cost => '1.23').cost_free?.should be_false
64
+ Osm::Event.new(:cost => '0.00').cost_free?.should be_true
65
+ end
66
+
54
67
  it "Sorts by start, name then ID (unless IDs are equal)" do
55
68
  e1 = Osm::Event.new(:start => '2000-01-01 01:00:00', :name => 'An event', :id => 1)
56
69
  e2 = Osm::Event.new(:start => '2000-01-02 01:00:00', :name => 'An event', :id => 2)
@@ -105,7 +118,7 @@ describe "Event" do
105
118
  describe "Using the API" do
106
119
 
107
120
  before :each do
108
- events_body = {
121
+ @events_body = {
109
122
  'identifier' => 'eventid',
110
123
  'label' => 'name',
111
124
  'items' => [{
@@ -126,10 +139,11 @@ describe "Event" do
126
139
  'disablereminders' => '1',
127
140
  'attendancelimit' => '3',
128
141
  'limitincludesleaders' => '1',
142
+ 'allowbooking' => '1',
129
143
  }]
130
144
  }
131
145
 
132
- event_body = {
146
+ @event_body = {
133
147
  'eventid' => '2',
134
148
  'name' => 'An Event',
135
149
  'startdate' => '2001-01-02',
@@ -152,10 +166,11 @@ describe "Event" do
152
166
  'structure' => [],
153
167
  'attendancelimit' => '3',
154
168
  'limitincludesleaders' => '1',
169
+ 'allowbooking' => '1',
155
170
  }
156
171
 
157
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents&sectionid=1&showArchived=true", :body => events_body.to_json)
158
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvent&sectionid=1&eventid=2", :body => event_body.to_json)
172
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents&sectionid=1&showArchived=true", :body => @events_body.to_json)
173
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvent&sectionid=1&eventid=2", :body => @event_body.to_json)
159
174
 
160
175
  Osm::Model.stub(:get_user_permissions) { {:events => [:read, :write]} }
161
176
  end
@@ -181,12 +196,22 @@ describe "Event" do
181
196
  event.reminders.should == false
182
197
  event.attendance_limit.should == 3
183
198
  event.attendance_limit_includes_leaders.should == true
199
+ event.allow_booking.should == true
184
200
  event.columns[0].id.should == 'f_1'
185
201
  event.columns[0].name.should == 'Name'
186
202
  event.columns[0].label.should == 'Label'
187
203
  event.valid?.should be_true
188
204
  end
189
205
 
206
+ it 'Handles cost of "-1" for TBC' do
207
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvent&sectionid=1&eventid=2", :body => @event_body.merge({'cost' => '-1'}).to_json)
208
+
209
+ events = Osm::Event.get_for_section(@api, 1)
210
+ event = events[0]
211
+ event.cost.should == 'TBC'
212
+ event.valid?.should be_true
213
+ end
214
+
190
215
  it "From cache" do
191
216
  events = Osm::Event.get_for_section(@api, 1)
192
217
  HTTParty.should_not_receive(:post)
@@ -349,50 +374,104 @@ describe "Event" do
349
374
 
350
375
  end
351
376
 
352
- it "Create (succeded)" do
353
- url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent&sectionid=1'
354
- post_data = {
355
- 'apiid' => @CONFIGURATION[:api][:osm][:id],
356
- 'token' => @CONFIGURATION[:api][:osm][:token],
357
- 'userid' => 'user_id',
358
- 'secret' => 'secret',
359
- 'name' => 'Test event',
360
- 'startdate' => '2000-01-02',
361
- 'enddate' => '2001-02-03',
362
- 'starttime' => '03:04:05',
363
- 'endtime' => '04:05:06',
364
- 'cost' => '1.23',
365
- 'location' => 'Somewhere',
366
- 'notes' => 'none',
367
- 'confdate' => '2000-01-01',
368
- 'allowChanges' => 'true',
369
- 'disablereminders' => 'false',
370
- 'attendancelimit' => 3,
371
- 'limitincludesleaders' => true,
372
- }
377
+ describe "Create (succeded)" do
373
378
 
374
- Osm::Event.stub(:get_for_section) { [] }
375
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
379
+ it "Normal" do
380
+ url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent&sectionid=1'
381
+ post_data = {
382
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
383
+ 'token' => @CONFIGURATION[:api][:osm][:token],
384
+ 'userid' => 'user_id',
385
+ 'secret' => 'secret',
386
+ 'name' => 'Test event',
387
+ 'startdate' => '2000-01-02',
388
+ 'enddate' => '2001-02-03',
389
+ 'starttime' => '03:04:05',
390
+ 'endtime' => '04:05:06',
391
+ 'cost' => '1.23',
392
+ 'location' => 'Somewhere',
393
+ 'notes' => 'none',
394
+ 'confdate' => '2000-01-01',
395
+ 'allowChanges' => 'true',
396
+ 'disablereminders' => 'false',
397
+ 'attendancelimit' => 3,
398
+ 'limitincludesleaders' => 'true',
399
+ 'allowbooking' => 'true',
400
+ }
401
+
402
+ Osm::Event.stub(:get_for_section) { [] }
403
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
404
+
405
+ event = Osm::Event.create(@api, {
406
+ :section_id => 1,
407
+ :name => 'Test event',
408
+ :start => DateTime.new(2000, 1, 2, 3, 4, 5),
409
+ :finish => DateTime.new(2001, 2, 3, 4, 5, 6),
410
+ :cost => '1.23',
411
+ :location => 'Somewhere',
412
+ :notes => 'none',
413
+ :columns => [],
414
+ :notepad => '',
415
+ :public_notepad => '',
416
+ :confirm_by_date => Date.new(2000, 1, 1),
417
+ :allow_changes => true,
418
+ :reminders => true,
419
+ :attendance_limit => 3,
420
+ :attendance_limit_includes_leaders => true,
421
+ :allow_booking => true,
422
+ })
423
+ event.should_not be_nil
424
+ event.id.should == 2
425
+ end
426
+
427
+ it "TBC cost" do
428
+ url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent&sectionid=1'
429
+ post_data = {
430
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
431
+ 'token' => @CONFIGURATION[:api][:osm][:token],
432
+ 'userid' => 'user_id',
433
+ 'secret' => 'secret',
434
+ 'name' => 'Test event',
435
+ 'startdate' => '2000-01-02',
436
+ 'enddate' => '2001-02-03',
437
+ 'starttime' => '03:04:05',
438
+ 'endtime' => '04:05:06',
439
+ 'cost' => '-1',
440
+ 'location' => 'Somewhere',
441
+ 'notes' => 'none',
442
+ 'confdate' => '2000-01-01',
443
+ 'allowChanges' => 'true',
444
+ 'disablereminders' => 'false',
445
+ 'attendancelimit' => 3,
446
+ 'limitincludesleaders' => 'true',
447
+ 'allowbooking' => 'true',
448
+ }
449
+
450
+ Osm::Event.stub(:get_for_section) { [] }
451
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
452
+
453
+ event = Osm::Event.create(@api, {
454
+ :section_id => 1,
455
+ :name => 'Test event',
456
+ :start => DateTime.new(2000, 1, 2, 3, 4, 5),
457
+ :finish => DateTime.new(2001, 2, 3, 4, 5, 6),
458
+ :cost => 'TBC',
459
+ :location => 'Somewhere',
460
+ :notes => 'none',
461
+ :columns => [],
462
+ :notepad => '',
463
+ :public_notepad => '',
464
+ :confirm_by_date => Date.new(2000, 1, 1),
465
+ :allow_changes => true,
466
+ :reminders => true,
467
+ :attendance_limit => 3,
468
+ :attendance_limit_includes_leaders => true,
469
+ :allow_booking => true,
470
+ })
471
+ event.should_not be_nil
472
+ event.id.should == 2
473
+ end
376
474
 
377
- event = Osm::Event.create(@api, {
378
- :section_id => 1,
379
- :name => 'Test event',
380
- :start => DateTime.new(2000, 1, 2, 3, 4, 5),
381
- :finish => DateTime.new(2001, 2, 3, 4, 5, 6),
382
- :cost => '1.23',
383
- :location => 'Somewhere',
384
- :notes => 'none',
385
- :columns => [],
386
- :notepad => '',
387
- :public_notepad => '',
388
- :confirm_by_date => Date.new(2000, 1, 1),
389
- :allow_changes => true,
390
- :reminders => true,
391
- :attendance_limit => 3,
392
- :attendance_limit_includes_leaders => true,
393
- })
394
- event.should_not be_nil
395
- event.id.should == 2
396
475
  end
397
476
 
398
477
  it "Create (failed)" do
@@ -418,53 +497,107 @@ describe "Event" do
418
497
  end
419
498
 
420
499
 
421
- it "Update (succeded)" do
422
- url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent&sectionid=1'
423
- post_data = {
424
- 'apiid' => @CONFIGURATION[:api][:osm][:id],
425
- 'token' => @CONFIGURATION[:api][:osm][:token],
426
- 'userid' => 'user_id',
427
- 'secret' => 'secret',
428
- 'name' => 'Test event',
429
- 'startdate' => '2000-01-02',
430
- 'enddate' => '2001-02-03',
431
- 'starttime' => '03:04:05',
432
- 'endtime' => '04:05:06',
433
- 'cost' => '1.23',
434
- 'location' => 'Somewhere',
435
- 'notes' => 'none',
436
- 'eventid' => 2,
437
- 'confdate' => '',
438
- 'allowChanges' => 'true',
439
- 'disablereminders' => 'false',
440
- 'attendancelimit' => 3,
441
- 'limitincludesleaders' => true,
442
- }
500
+ describe "Update (succeded)" do
443
501
 
444
- HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
445
- HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/events.php?action=saveNotepad&sectionid=1', {:body=>{"eventid"=>2, "notepad"=>"notepad", "userid"=>"user_id", "secret"=>"secret", "apiid"=>"1", "token"=>"API TOKEN"}}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
446
- HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/events.php?action=saveNotepad&sectionid=1', {:body=>{"eventid"=>2, "pnnotepad"=>"public notepad", "userid"=>"user_id", "secret"=>"secret", "apiid"=>"1", "token"=>"API TOKEN"}}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
502
+ it "Normal" do
503
+ url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent&sectionid=1'
504
+ post_data = {
505
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
506
+ 'token' => @CONFIGURATION[:api][:osm][:token],
507
+ 'userid' => 'user_id',
508
+ 'secret' => 'secret',
509
+ 'name' => 'Test event',
510
+ 'startdate' => '2000-01-02',
511
+ 'enddate' => '2001-02-03',
512
+ 'starttime' => '03:04:05',
513
+ 'endtime' => '04:05:06',
514
+ 'cost' => '1.23',
515
+ 'location' => 'Somewhere',
516
+ 'notes' => 'none',
517
+ 'eventid' => 2,
518
+ 'confdate' => '',
519
+ 'allowChanges' => 'true',
520
+ 'disablereminders' => 'false',
521
+ 'attendancelimit' => 3,
522
+ 'limitincludesleaders' => 'true',
523
+ 'allowbooking' => 'true',
524
+ }
525
+
526
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
527
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/events.php?action=saveNotepad&sectionid=1', {:body=>{"eventid"=>2, "notepad"=>"notepad", "userid"=>"user_id", "secret"=>"secret", "apiid"=>"1", "token"=>"API TOKEN"}}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
528
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/events.php?action=saveNotepad&sectionid=1', {:body=>{"eventid"=>2, "pnnotepad"=>"public notepad", "userid"=>"user_id", "secret"=>"secret", "apiid"=>"1", "token"=>"API TOKEN"}}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
529
+
530
+ event = Osm::Event.new(
531
+ :section_id => 1,
532
+ :name => 'Test event',
533
+ :start => DateTime.new(2000, 01, 02, 03, 04, 05),
534
+ :finish => DateTime.new(2001, 02, 03, 04, 05, 06),
535
+ :cost => '1.23',
536
+ :location => 'Somewhere',
537
+ :notes => 'none',
538
+ :id => 2,
539
+ :confirm_by_date => nil,
540
+ :allow_changes => true,
541
+ :reminders => true,
542
+ :notepad => '',
543
+ :public_notepad => '',
544
+ :attendance_limit => 3,
545
+ :attendance_limit_includes_leaders => true,
546
+ :allow_booking => true,
547
+ )
548
+ event.notepad = 'notepad'
549
+ event.public_notepad = 'public notepad'
550
+ event.update(@api).should be_true
551
+ end
552
+
553
+ it "TBC cost" do
554
+ url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent&sectionid=1'
555
+ post_data = {
556
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
557
+ 'token' => @CONFIGURATION[:api][:osm][:token],
558
+ 'userid' => 'user_id',
559
+ 'secret' => 'secret',
560
+ 'name' => 'Test event',
561
+ 'startdate' => '2000-01-02',
562
+ 'enddate' => '2001-02-03',
563
+ 'starttime' => '03:04:05',
564
+ 'endtime' => '04:05:06',
565
+ 'cost' => '-1',
566
+ 'location' => 'Somewhere',
567
+ 'notes' => 'none',
568
+ 'eventid' => 2,
569
+ 'confdate' => '',
570
+ 'allowChanges' => 'true',
571
+ 'disablereminders' => 'false',
572
+ 'attendancelimit' => 3,
573
+ 'limitincludesleaders' => 'true',
574
+ 'allowbooking' => 'true',
575
+ }
576
+
577
+ HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
578
+
579
+ event = Osm::Event.new(
580
+ :section_id => 1,
581
+ :name => 'Test event',
582
+ :start => DateTime.new(2000, 01, 02, 03, 04, 05),
583
+ :finish => DateTime.new(2001, 02, 03, 04, 05, 06),
584
+ :cost => '1.23',
585
+ :location => 'Somewhere',
586
+ :notes => 'none',
587
+ :id => 2,
588
+ :confirm_by_date => nil,
589
+ :allow_changes => true,
590
+ :reminders => true,
591
+ :notepad => '',
592
+ :public_notepad => '',
593
+ :attendance_limit => 3,
594
+ :attendance_limit_includes_leaders => true,
595
+ :allow_booking => true,
596
+ )
597
+ event.cost = 'TBC'
598
+ event.update(@api).should be_true
599
+ end
447
600
 
448
- event = Osm::Event.new(
449
- :section_id => 1,
450
- :name => 'Test event',
451
- :start => DateTime.new(2000, 01, 02, 03, 04, 05),
452
- :finish => DateTime.new(2001, 02, 03, 04, 05, 06),
453
- :cost => '1.23',
454
- :location => 'Somewhere',
455
- :notes => 'none',
456
- :id => 2,
457
- :confirm_by_date => nil,
458
- :allow_changes => true,
459
- :reminders => true,
460
- :notepad => '',
461
- :public_notepad => '',
462
- :attendance_limit => 3,
463
- :attendance_limit_includes_leaders => true,
464
- )
465
- event.notepad = 'notepad'
466
- event.public_notepad = 'public notepad'
467
- event.update(@api).should be_true
468
601
  end
469
602
 
470
603
  it "Update (failed)" do
@@ -36,8 +36,8 @@ describe "Register" do
36
36
  :grouping_id => '3',
37
37
  :total => 4,
38
38
  :attendance => {
39
- Date.new(2012, 1, 10) => 'Yes',
40
- Date.new(2012, 1, 24) => 'No',
39
+ Date.new(2012, 1, 10) => :yes,
40
+ Date.new(2012, 1, 24) => :unadvised_absent,
41
41
  }
42
42
  )
43
43
 
@@ -48,8 +48,8 @@ describe "Register" do
48
48
  rd.last_name.should == 'B'
49
49
  rd.total.should == 4
50
50
  rd.attendance.should == {
51
- Date.new(2012, 01, 10) => 'Yes',
52
- Date.new(2012, 01, 24) => 'No'
51
+ Date.new(2012, 01, 10) => :yes,
52
+ Date.new(2012, 01, 24) => :unadvised_absent
53
53
  }
54
54
  rd.valid?.should be_true
55
55
  end
@@ -65,6 +65,20 @@ describe "Register" do
65
65
  data.sort.should == [d1, d2, d3, d4, d5]
66
66
  end
67
67
 
68
+ it "Reports if a member was present on a date" do
69
+ date = Date.new(2000, 1, 1)
70
+ Osm::Register::Attendance.new(:attendance => {date => :yes}).present_on?(date).should be_true
71
+ Osm::Register::Attendance.new(:attendance => {date => :known_absent}).present_on?(date).should be_false
72
+ Osm::Register::Attendance.new(:attendance => {date => :unknown_absent}).present_on?(date).should be_false
73
+ end
74
+
75
+ it "Reports if a member was absent on a date" do
76
+ date = Date.new(2000, 1, 1)
77
+ Osm::Register::Attendance.new(:attendance => {date => :yes}).absent_on?(date).should be_false
78
+ Osm::Register::Attendance.new(:attendance => {date => :known_absent}).absent_on?(date).should be_true
79
+ Osm::Register::Attendance.new(:attendance => {date => :unknown_absent}).absent_on?(date).should be_true
80
+ end
81
+
68
82
 
69
83
  describe "Using the API" do
70
84
 
@@ -96,14 +110,20 @@ describe "Register" do
96
110
  ]
97
111
  }
98
112
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/users.php?action=register&sectionid=1&termid=2", :body => data.to_json)
113
+ Osm::Register.stub(:get_structure) { [
114
+ Osm::Register::Field.new(:id => '2000-01-01', :name => 'Name', :tooltip => 'Tooltip'),
115
+ Osm::Register::Field.new(:id => '2000-01-02', :name => 'Name', :tooltip => 'Tooltip'),
116
+ Osm::Register::Field.new(:id => '2000-01-03', :name => 'Name', :tooltip => 'Tooltip'),
117
+ ] }
99
118
 
100
119
  register = Osm::Register.get_attendance(@api, 1, 2)
101
120
  register.is_a?(Array).should be_true
102
121
  register.size.should == 1
103
122
  reg = register[0]
104
123
  reg.attendance.should == {
105
- Date.new(2000, 1, 1) => 'Yes',
106
- Date.new(2000, 1, 2) => 'No'
124
+ Date.new(2000, 1, 1) => :yes,
125
+ Date.new(2000, 1, 2) => :advised_absent,
126
+ Date.new(2000, 1, 3) => :unadvised_absent,
107
127
  }
108
128
  reg.first_name.should == 'First'
109
129
  reg.last_name.should == 'Last'
@@ -135,7 +155,7 @@ describe "Register" do
135
155
  :section => Osm::Section.new(:id=>1, :type=>:cubs),
136
156
  :term => 2,
137
157
  :evening => Date.new(2000, 1, 2),
138
- :attendance => 'Yes',
158
+ :attendance => :yes,
139
159
  :members => 3,
140
160
  :completed_badge_requirements => [{'a'=>'A'}, {'b'=>'B'}]
141
161
  }).should be_true
@@ -163,6 +183,7 @@ describe "Register" do
163
183
  ]
164
184
  }
165
185
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/users.php?action=register&sectionid=1&termid=2", :body => data.to_json)
186
+ Osm::Register.stub(:get_structure) { [] }
166
187
 
167
188
  register = Osm::Register.get_attendance(@api, 1, 2)
168
189
  register.is_a?(Array).should be_true
@@ -172,7 +193,7 @@ describe "Register" do
172
193
  reg.last_name.should == 'Last'
173
194
  end
174
195
 
175
- it "Handles no data" do
196
+ it "Handles no data getting structure" do
176
197
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/users.php?action=registerStructure&sectionid=1&termid=2", :body => '')
177
198
  register_structure = Osm::Register.get_structure(@api, 1, 2)
178
199
  register_structure.is_a?(Array).should be_true
@@ -33,6 +33,7 @@ describe "Section" do
33
33
  :myscout_email_address_copy => '',
34
34
  :myscout_badges_partial => true,
35
35
  :myscout_programme_summary => true,
36
+ :myscout_programme_times => true,
36
37
  :myscout_event_reminder_count => 4,
37
38
  :myscout_event_reminder_frequency => 5,
38
39
  :myscout_payment_reminder_count => 6,
@@ -69,6 +70,7 @@ describe "Section" do
69
70
  section.myscout_email_address_copy.should == ''
70
71
  section.myscout_badges_partial.should == true
71
72
  section.myscout_programme_summary.should == true
73
+ section.myscout_programme_times.should == true
72
74
  section.myscout_event_reminder_count.should == 4
73
75
  section.myscout_event_reminder_frequency.should == 5
74
76
  section.myscout_payment_reminder_count.should == 6
@@ -97,7 +99,7 @@ describe "Section" do
97
99
 
98
100
  before :each do
99
101
  body = [
100
- {"sectionConfig"=>"{\"subscription_level\":1,\"subscription_expires\":\"2013-01-05\",\"sectionType\":\"beavers\",\"columnNames\":{\"column_names\":\"names\"},\"numscouts\":10,\"hasUsedBadgeRecords\":true,\"hasProgramme\":true,\"extraRecords\":[{\"name\":\"Flexi Record 1\",\"extraid\":\"111\"}],\"wizard\":\"false\",\"fields\":{\"fields\":true},\"intouch\":{\"intouch_fields\":true},\"mobFields\":{\"mobile_fields\":true},\"gocardless\":\"true\",\"portal\":{\"paymentRemindFrequency\":\"7\",\"paymentRemindCount\":\"6\",\"eventRemindFrequency\":\"5\",\"eventRemindCount\":\"4\",\"badgesPartial\":1,\"programmeSummary\":1,\"emailAddress\":\"send_from@example.com\",\"emailAddressCopy\":null,\"payments\":1,\"badges\":1,\"emails\":{\"email1\":\"true\",\"email2\":\"false\"},\"events\":1,\"programme\":1},\"portalExpires\":{\"events\":\"2013-01-06\",\"eventsA\":1,\"badges\":\"2013-01-07\",\"badgesA\":1,\"programme\":\"2013-01-08\",\"programmeA\":1}}", "groupname"=>"3rd Somewhere", "groupid"=>"3", "groupNormalised"=>"1", "sectionid"=>"1", "sectionname"=>"Section 1", "section"=>"beavers", "isDefault"=>"1", "permissions"=>{"badge"=>10, "member"=>20, "user"=>100, "register"=>100, "contact"=>100, "programme"=>100, "originator"=>1, "events"=>100, "finance"=>100, "flexi"=>100}},
102
+ {"sectionConfig"=>"{\"subscription_level\":1,\"subscription_expires\":\"2013-01-05\",\"sectionType\":\"beavers\",\"columnNames\":{\"column_names\":\"names\"},\"numscouts\":10,\"hasUsedBadgeRecords\":true,\"hasProgramme\":true,\"extraRecords\":[{\"name\":\"Flexi Record 1\",\"extraid\":\"111\"}],\"wizard\":\"false\",\"fields\":{\"fields\":true},\"intouch\":{\"intouch_fields\":true},\"mobFields\":{\"mobile_fields\":true},\"gocardless\":\"true\",\"portal\":{\"paymentRemindFrequency\":\"7\",\"paymentRemindCount\":\"6\",\"eventRemindFrequency\":\"5\",\"eventRemindCount\":\"4\",\"badgesPartial\":1,\"programmeTimes\":1,\"programmeSummary\":1,\"emailAddress\":\"send_from@example.com\",\"emailAddressCopy\":null,\"payments\":1,\"badges\":1,\"emails\":{\"email1\":\"true\",\"email2\":\"false\"},\"events\":1,\"programme\":1},\"portalExpires\":{\"events\":\"2013-01-06\",\"eventsA\":1,\"badges\":\"2013-01-07\",\"badgesA\":1,\"programme\":\"2013-01-08\",\"programmeA\":1}}", "groupname"=>"3rd Somewhere", "groupid"=>"3", "groupNormalised"=>"1", "sectionid"=>"1", "sectionname"=>"Section 1", "section"=>"beavers", "isDefault"=>"1", "permissions"=>{"badge"=>10, "member"=>20, "user"=>100, "register"=>100, "contact"=>100, "programme"=>100, "originator"=>1, "events"=>100, "finance"=>100, "flexi"=>100}},
101
103
  {"sectionConfig"=>"{\"subscription_level\":3,\"subscription_expires\":\"2013-01-05\",\"sectionType\":\"cubs\",\"columnNames\":{\"phone1\":\"Home Phone\",\"phone2\":\"Parent 1 Phone\",\"address\":\"Member's Address\",\"phone3\":\"Parent 2 Phone\",\"address2\":\"Address 2\",\"phone4\":\"Alternate Contact Phone\",\"subs\":\"Gender\",\"email1\":\"Parent 1 Email\",\"medical\":\"Medical / Dietary\",\"email2\":\"Parent 2 Email\",\"ethnicity\":\"Gift Aid\",\"email3\":\"Member's Email\",\"religion\":\"Religion\",\"email4\":\"Email 4\",\"school\":\"School\"},\"numscouts\":10,\"hasUsedBadgeRecords\":true,\"hasProgramme\":true,\"extraRecords\":[],\"wizard\":\"false\",\"fields\":{\"email1\":true,\"email2\":true,\"email3\":true,\"email4\":false,\"address\":true,\"address2\":false,\"phone1\":true,\"phone2\":true,\"phone3\":true,\"phone4\":true,\"school\":false,\"religion\":true,\"ethnicity\":true,\"medical\":true,\"patrol\":true,\"subs\":true,\"saved\":true},\"intouch\":{\"address\":true,\"address2\":false,\"email1\":false,\"email2\":false,\"email3\":false,\"email4\":false,\"phone1\":true,\"phone2\":true,\"phone3\":true,\"phone4\":true,\"medical\":false},\"mobFields\":{\"email1\":false,\"email2\":false,\"email3\":false,\"email4\":false,\"address\":true,\"address2\":false,\"phone1\":true,\"phone2\":true,\"phone3\":true,\"phone4\":true,\"school\":false,\"religion\":false,\"ethnicity\":true,\"medical\":true,\"patrol\":true,\"subs\":false}}", "groupname"=>"1st Somewhere", "groupid"=>"1", "groupNormalised"=>"1", "sectionid"=>"2", "sectionname"=>"Section 2", "section"=>"cubs", "isDefault"=>"0", "permissions"=>{"badge"=>100, "member"=>100, "user"=>100, "register"=>100, "contact"=>100, "programme"=>100, "originator"=>1, "events"=>100, "finance"=>100, "flexi"=>100}}
102
104
  ]
103
105
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body.to_json)
@@ -136,6 +138,7 @@ describe "Section" do
136
138
  section.myscout_email_address_copy.should == ''
137
139
  section.myscout_badges_partial.should == true
138
140
  section.myscout_programme_summary.should == true
141
+ section.myscout_programme_times.should == true
139
142
  section.myscout_event_reminder_count.should == 4
140
143
  section.myscout_event_reminder_frequency.should == 5
141
144
  section.myscout_payment_reminder_count.should == 6
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Osm
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
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: 0.4.2
4
+ version: 0.5.0
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-03-25 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport