osm 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## Version 0.2.2
2
+
3
+ * Add comparing and sorting (using <=>, <, <=, >, >= and between?) to each model
4
+ * Activity - id then version
5
+ * Activity::File - activity\_id then name
6
+ * Activity::Version - activity\_id then version
7
+ * ApiAccess - id
8
+ * Event - start, name then id (shortcuts, returning 0 if ids are equal)
9
+ * Event::Column - event then id
10
+ * Event::Attendance - event then row
11
+ * FlexiRecord - section\_id then name
12
+ * FlexiRecord::Column - flexi\_record then id (system ones first then user ones)
13
+ * FlexiRecord::Data - flexi\_record, grouping\_id then member\_id
14
+ * Grouping - section\_id then name
15
+ * Meeting - section\_id, date, start\_time then id
16
+ * Meeting::Activity - title then activity\_id
17
+ * Member - section\_id, grouping\_id, grouping\_leader (descending), last\_name then first\_name
18
+ * Register::Field - id
19
+ * Register::Attendance - section\_id, grouping\_id, last\_name then first\_name
20
+ * Section - group\_name, type (by age) then name
21
+ * Term - section\_id, start then id
22
+
1
23
  ## Version 0.2.0
2
24
 
3
25
  * Raises Forbidden exception if:
data/lib/osm/activity.rb CHANGED
@@ -253,6 +253,13 @@ module Osm
253
253
  end
254
254
  end
255
255
 
256
+ # Compare Activity based on id then version
257
+ def <=>(another)
258
+ result = self.id <=> another.try(:id)
259
+ result = self.version <=> another.try(:version) if result == 0
260
+ return result
261
+ end
262
+
256
263
 
257
264
  private
258
265
  class File
@@ -284,6 +291,13 @@ module Osm
284
291
  # Initialize a new Term
285
292
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
286
293
 
294
+ # Compare File based on activity_id then name
295
+ def <=>(another)
296
+ result = self.activity_id <=> another.try(:activity_id)
297
+ result = self.name <=> another.try(:name) if result == 0
298
+ return result
299
+ end
300
+
287
301
  end # Class Activity::File
288
302
 
289
303
  class Badge
@@ -356,6 +370,13 @@ module Osm
356
370
  # Initialize a new Version
357
371
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
358
372
 
373
+ # Compare Version based on activity_id then version
374
+ def <=>(another)
375
+ result = self.activity_id <=> another.try(:activity_id)
376
+ result = self.version <=> another.try(:version) if result == 0
377
+ return result
378
+ end
379
+
359
380
  end # Class Activity::Version
360
381
 
361
382
  end # Class Activity
@@ -106,6 +106,7 @@ module Osm
106
106
  # Initialize a new Term
107
107
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
108
108
 
109
+
109
110
  end # Class ApiAccess
110
111
 
111
112
  end # Module
data/lib/osm/event.rb CHANGED
@@ -321,6 +321,15 @@ module Osm
321
321
  return attendance_limit - attendees(api)
322
322
  end
323
323
 
324
+ # Compare Event based on start, name then id
325
+ def <=>(another)
326
+ return 0 if self.id == another.try(:id)
327
+ result = self.start <=> another.try(:start)
328
+ result = self.name <=> another.try(:name) if result == 0
329
+ result = self.id <=> another.try(:id) if result == 0
330
+ return result
331
+ end
332
+
324
333
 
325
334
  private
326
335
  def attendees(api)
@@ -357,6 +366,7 @@ module Osm
357
366
  end
358
367
  event.columns = columns
359
368
  return event
369
+
360
370
  end
361
371
 
362
372
 
@@ -437,6 +447,13 @@ module Osm
437
447
  return true
438
448
  end
439
449
 
450
+ # Compare Column based on event then id
451
+ def <=>(another)
452
+ result = self.event <=> another.try(:event)
453
+ result = self.id <=> another.try(:id) if result == 0
454
+ return result
455
+ end
456
+
440
457
  end # class Column
441
458
 
442
459
 
@@ -502,6 +519,13 @@ module Osm
502
519
  end
503
520
  end
504
521
 
522
+ # Compare Activity based on event then row
523
+ def <=>(another)
524
+ result = self.event <=> another.try(:event)
525
+ result = self.row <=> another.try(:row) if result == 0
526
+ return result
527
+ end
528
+
505
529
  end # Class Attendance
506
530
 
507
531
  end # Class Event
@@ -28,7 +28,7 @@ module Osm
28
28
  cache_key = ['flexi_record_columns', self.id]
29
29
 
30
30
  if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key)
31
- return Osm::Model.cache_read(api, cache_key)
31
+ return cache_read(api, cache_key)
32
32
  end
33
33
 
34
34
  data = api.perform_query("extras.php?action=getExtra&sectionid=#{self.section_id}&extraid=#{self.id}")
@@ -44,7 +44,7 @@ module Osm
44
44
  )
45
45
  end
46
46
  end
47
- Osm::Model.cache_write(api, cache_key, structure)
47
+ cache_write(api, cache_key, structure)
48
48
 
49
49
  return structure
50
50
  end
@@ -65,7 +65,7 @@ module Osm
65
65
  ActiveSupport::JSON.decode(data['config']).each do |field|
66
66
  if field['name'] == name
67
67
  # The cached fields for the flexi record will be out of date - remove them
68
- Osm::Model.cache_delete(api, ['flexi_record_columns', id])
68
+ cache_delete(api, ['flexi_record_columns', id])
69
69
  return true
70
70
  end
71
71
  end
@@ -85,7 +85,7 @@ module Osm
85
85
  cache_key = ['flexi_record_data', id, term_id]
86
86
 
87
87
  if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key)
88
- return Osm::Model.cache_read(api, cache_key)
88
+ return cache_read(api, cache_key)
89
89
  end
90
90
 
91
91
  data = api.perform_query("extras.php?action=getExtraRecords&sectionid=#{section.id}&extraid=#{id}&termid=#{term_id}&section=#{section.type}")
@@ -112,17 +112,15 @@ module Osm
112
112
  end
113
113
  end
114
114
 
115
- Osm::Model.cache_write(api, cache_key, to_return)
115
+ cache_write(api, cache_key, to_return)
116
116
  return to_return
117
117
  end
118
118
 
119
-
119
+ # Compare Activity based on section_id then name
120
120
  def <=>(another)
121
- begin
122
- return self.name <=> another.name
123
- rescue NoMethodError
124
- return 1
125
- end
121
+ result = self.section_id <=> another.try(:section_id)
122
+ result = self.name <=> another.try(:name) if result == 0
123
+ return result
126
124
  end
127
125
 
128
126
 
@@ -208,6 +206,26 @@ module Osm
208
206
  return true
209
207
  end
210
208
 
209
+ # Compare Column based on flexi_record then id
210
+ def <=>(another)
211
+ result = self.flexi_record <=> another.try(:flexi_record)
212
+ if result == 0
213
+ if id.match(/\Af_\d+\Z/)
214
+ # This is a user column
215
+ unless another.try(:id).to_s.match(/\Af_\d+\Z/)
216
+ return 1
217
+ end
218
+ else
219
+ # This is a system column
220
+ if another.try(:id).to_s.match(/\Af_\d+\Z/)
221
+ return -1
222
+ end
223
+ end
224
+ result = self.id <=> another.try(:id)
225
+ end
226
+ return result
227
+ end
228
+
211
229
  end # Class FlexiRecord::Column
212
230
 
213
231
 
@@ -280,6 +298,14 @@ module Osm
280
298
  return updated
281
299
  end
282
300
 
301
+ # Compare Data based on flexi_record, grouping_id then member_id
302
+ def <=>(another)
303
+ result = self.flexi_record <=> another.try(:flexi_record)
304
+ result = self.grouping_id <=> another.try(:grouping_id) if result == 0
305
+ result = self.member_id <=> another.try(:member_id) if result == 0
306
+ return result
307
+ end
308
+
283
309
  end # Class FlexiRecord::Data
284
310
 
285
311
  end # Class FlexiRecord
data/lib/osm/grouping.rb CHANGED
@@ -104,6 +104,12 @@ module Osm
104
104
  return result
105
105
  end
106
106
 
107
+ # Compare Grouping based on section_id then name
108
+ def <=>(another)
109
+ result = self.section_id <=> another.try(:section_id)
110
+ result = self.name <=> another.try(:name) if result == 0
111
+ return result
112
+ end
107
113
 
108
114
  end # Class Grouping
109
115
 
data/lib/osm/meeting.rb CHANGED
@@ -241,26 +241,18 @@ module Osm
241
241
  return data
242
242
  end
243
243
 
244
-
244
+ # Compare Meeting based on section_id, date, start_time then id
245
245
  def <=>(another)
246
- begin
247
- compare = self.section_id <=> another.section_id
248
- return compare unless compare == 0
249
-
250
- compare = self.date <=> another.date
251
- return compare unless compare == 0
252
-
246
+ result = self.section_id <=> another.try(:section_id)
247
+ result = self.date <=> another.try(:date) if result == 0
248
+ if result == 0
253
249
  my_start_time = self.start_time.split(':').map{ |i| i.to_i }
254
250
  another_start_time = another.start_time.split(':').map{ |i| i.to_i }
255
- compare = my_start_time[0] <=> another_start_time[0]
256
- return compare unless compare == 0
257
- compare = my_start_time[1] <=> another_start_time[1]
258
- return compare unless compare == 0
259
-
260
- return self.id <=> another.id
261
- rescue NoMethodError
262
- return 0
263
- end
251
+ result = my_start_time[0] <=> another_start_time[0] if result == 0
252
+ result = compare = my_start_time[1] <=> another_start_time[1] if result == 0
253
+ end
254
+ result = self.id <=> another.try(:id) if result == 0
255
+ return result
264
256
  end
265
257
 
266
258
 
@@ -289,6 +281,13 @@ module Osm
289
281
  # Initialize a new Meeting::Activity
290
282
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
291
283
 
284
+ # Compare Activity based on title then activity_id
285
+ def <=>(another)
286
+ result = self.title <=> another.try(:title)
287
+ result = self.activity_id <=> another.try(:activity_id) if result == 0
288
+ return result
289
+ end
290
+
292
291
  end # Class Meeting::Activity
293
292
 
294
293
  end # Class Meeting
data/lib/osm/member.rb CHANGED
@@ -389,6 +389,16 @@ module Osm
389
389
  return "https://www.onlinescoutmanager.co.uk/parents/#{link_to}.php?sc=#{self.id}&se=#{section_id}&c=#{@myscout_link_key}"
390
390
  end
391
391
 
392
+ # Compare Activity based on section_id, grouping_id, grouping_leader (descending), last_name then first_name
393
+ def <=>(another)
394
+ result = self.section_id <=> another.try(:section_id)
395
+ result = self.grouping_id <=> another.try(:grouping_id) if result == 0
396
+ result = -(self.grouping_leader <=> another.try(:grouping_leader)) if result == 0
397
+ result = self.last_name <=> another.try(:last_name) if result == 0
398
+ result = self.first_name <=> another.try(:last_name) if result == 0
399
+ return result
400
+ end
401
+
392
402
  end # Class Member
393
403
 
394
404
  end # Module
data/lib/osm/model.rb CHANGED
@@ -38,10 +38,34 @@ module Osm
38
38
  end
39
39
 
40
40
 
41
+ # Default to_i conversion is of id
41
42
  def to_i
42
- id
43
+ id.to_i
43
44
  end
44
45
 
46
+ # Default compare based on id
47
+ def <=>(another)
48
+ return self.id <=> another.try(:id)
49
+ end
50
+
51
+ # Add other compare functions
52
+ def <(another)
53
+ send('<=>', another) < 0
54
+ end
55
+ def <=(another)
56
+ send('<=>', another) <= 0
57
+ end
58
+ def >(another)
59
+ send('<=>', another) > 0
60
+ end
61
+ def >=(another)
62
+ send('<=>', another) >= 0
63
+ end
64
+ def between?(min, max)
65
+ (send('<=>', min) > 0) && (send('<=>', max) < 0)
66
+ end
67
+
68
+
45
69
  # Get a list of attributes which have changed
46
70
  # @return Array[String] the names of attributes which have changed
47
71
  def changed_attributes
data/lib/osm/register.rb CHANGED
@@ -143,10 +143,17 @@ module Osm
143
143
  validates_presence_of :name
144
144
  validates_presence_of :tooltip, :allow_blank => true
145
145
 
146
+
146
147
  # @!method initialize
147
148
  # Initialize a new RegisterField
148
149
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
149
150
 
151
+
152
+ # Compare Field based on id then version
153
+ def <=>(another)
154
+ return self.id <=> another.try(:id)
155
+ end
156
+
150
157
  end # Class Register::Field
151
158
 
152
159
 
@@ -185,11 +192,22 @@ module Osm
185
192
 
186
193
  validates :attendance, :hash => {:key_type => Date, :value_in => ['Yes', 'No', nil]}
187
194
 
195
+
188
196
  # @!method initialize
189
197
  # Initialize a new registerData
190
198
  # @param [Hash] attributes The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
191
199
 
192
- end # Class Register::Data
200
+
201
+ # Compare Attendance based on section_id, grouping_id, last_name then first_name
202
+ def <=>(another)
203
+ result = self.section_id <=> another.try(:section_id)
204
+ result = self.grouping_id <=> another.try(:grouping_id) if result == 0
205
+ result = self.last_name <=> another.try(:last_name) if result == 0
206
+ result = self.first_name <=> another.try(:last_name) if result == 0
207
+ return result
208
+ end
209
+
210
+ end # Class Register::Attendance
193
211
 
194
212
  end # Class Register
195
213
 
data/lib/osm/section.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Osm
2
2
 
3
3
  class Section < Osm::Model
4
- class FlexiRecord; end # Ensure the constant exists for the validators
5
-
6
4
  # @!attribute [rw] id
7
5
  # @return [Fixnum] the id for the section
8
6
  # @!attribute [rw] name
@@ -134,6 +132,7 @@ module Osm
134
132
  validates :intouch_fields, :hash => {:key_type => Symbol, :value_in => [true, false]}
135
133
  validates :mobile_fields, :hash => {:key_type => Symbol, :value_in => [true, false]}
136
134
  validates :myscout_emails, :hash => {:key_in => [:email1, :email2, :email3, :email4], :value_in => [true, false]}
135
+ validates :flexi_records, :array_of => {:item_type => Osm::FlexiRecord, :item_valid => true}
137
136
 
138
137
 
139
138
  # @!method initialize
@@ -356,27 +355,18 @@ module Osm
356
355
  }[subscription_level]
357
356
  end
358
357
 
358
+ # Compare Section based on group_name type (age order), then name
359
359
  def <=>(another)
360
- begin
361
- compare_group_name = group_name <=> another.group_name
362
- return compare_group_name unless compare_group_name == 0
363
-
364
- return 0 if type == another.type
365
- [:beavers, :cubs, :scouts, :explorers, :waiting, :adults].each do |type|
366
- return -1 if type == type
367
- return 1 if another.type == type
360
+ result = self.group_name <=> another.try(:group_name)
361
+ result = 0 if self.type == another.try(:type) && result == 0
362
+ [:beavers, :cubs, :scouts, :explorers, :waiting, :adults].each do |type|
363
+ if result == 0
364
+ result = -1 if self.type == type
365
+ result = 1 if another.try(:type) == type
368
366
  end
369
- rescue NoMethodError
370
- return 1
371
- end
372
- end
373
-
374
- def ==(another)
375
- begin
376
- return self.id == another.id
377
- rescue NoMethodError
378
- return false
379
367
  end
368
+ result = self.name <=> another.try(:name) if result == 0
369
+ return result
380
370
  end
381
371
 
382
372
  end # Class Section
data/lib/osm/term.rb CHANGED
@@ -222,26 +222,12 @@ module Osm
222
222
  return (start <= date) && (finish >= date)
223
223
  end
224
224
 
225
+ # Compare Term based on section_id, start then id
225
226
  def <=>(another_term)
226
- begin
227
- compare = self.section_id <=> another_term.section_id
228
- return compare unless compare == 0
229
-
230
- compare = self.start <=> another_term.start
231
- return compare unless compare == 0
232
-
233
- return self.id <=> another_term.id
234
- rescue NoMethodError
235
- return 0
236
- end
237
- end
238
-
239
- def ==(another_term)
240
- begin
241
- return self.id == another_term.id
242
- rescue NoMethodError
243
- return false
244
- end
227
+ result = self.section_id <=> another_term.section_id
228
+ result = self.start <=> another_term.start if result == 0
229
+ result = self.id <=> another_term.id if result == 0
230
+ return result
245
231
  end
246
232
 
247
233
  end # Class Term
@@ -3,18 +3,51 @@ require 'spec_helper'
3
3
 
4
4
  describe "Activity" do
5
5
 
6
- it "Get OSM link" do
7
- activity = Osm::Activity.new(
8
- :id => 1,
9
- :running_time => 10,
10
- :title => 'Title',
11
- :description => 'Description',
12
- :resources => 'Resources',
13
- :instructions => 'Instructions',
14
- :location => :indoors,
15
- )
16
- activity.osm_link.should == 'https://www.onlinescoutmanager.co.uk/?l=p1'
6
+ it "Get OSM link" do
7
+ activity = Osm::Activity.new(
8
+ :id => 1,
9
+ :running_time => 10,
10
+ :title => 'Title',
11
+ :description => 'Description',
12
+ :resources => 'Resources',
13
+ :instructions => 'Instructions',
14
+ :location => :indoors,
15
+ )
16
+ activity.osm_link.should == 'https://www.onlinescoutmanager.co.uk/?l=p1'
17
+ end
18
+
19
+ it "Sorts by id then version" do
20
+ a1 = Osm::Activity.new(:id => 1, :version => 1)
21
+ a2 = Osm::Activity.new(:id => 2, :version => 1)
22
+ a3 = Osm::Activity.new(:id => 2, :version => 2)
23
+
24
+ activities = [a2, a3, a1]
25
+ activities.sort.should == [a1, a2, a3]
26
+ end
27
+
28
+
29
+ describe "Activity::File" do
30
+ it "Sorts by activity_id then name" do
31
+ a1 = Osm::Activity::File.new(:activity_id => 1, :name => 'a')
32
+ a2 = Osm::Activity::File.new(:activity_id => 2, :name => 'a')
33
+ a3 = Osm::Activity::File.new(:activity_id => 2, :name => 'b')
34
+
35
+ activities = [a2, a3, a1]
36
+ activities.sort.should == [a1, a2, a3]
37
+ end
38
+ end
39
+
40
+
41
+ describe "Activity::Version" do
42
+ it "Sorts by activity_id then version" do
43
+ a1 = Osm::Activity::File.new(:activity_id => 1, :version => 1)
44
+ a2 = Osm::Activity::File.new(:activity_id => 2, :version => 1)
45
+ a3 = Osm::Activity::File.new(:activity_id => 2, :version => 2)
46
+
47
+ activities = [a2, a3, a1]
48
+ activities.sort.should == [a1, a2, a3]
17
49
  end
50
+ end
18
51
 
19
52
 
20
53
  describe "Using The API" do
@@ -18,6 +18,14 @@ describe "API Access" do
18
18
  api_access.valid?.should be_true
19
19
  end
20
20
 
21
+ it "Sorts by id" do
22
+ a1 = Osm::ApiAccess.new(:id => 1)
23
+ a2 = Osm::ApiAccess.new(:id => 2)
24
+
25
+ data = [a2, a1]
26
+ data.sort.should == [a1, a2]
27
+ end
28
+
21
29
 
22
30
  describe "Using the API" do
23
31
 
@@ -51,24 +51,46 @@ describe "Event" do
51
51
  Osm::Event.new(:attendance_limit => 1).limited_attendance?.should be_true
52
52
  end
53
53
 
54
+ it "Sorts by start, name then ID (unless IDs are equal)" do
55
+ e1 = Osm::Event.new(:start => '2000-01-01 01:00:00', :name => 'An event', :id => 1)
56
+ e2 = Osm::Event.new(:start => '2000-01-02 01:00:00', :name => 'An event', :id => 2)
57
+ e3 = Osm::Event.new(:start => '2000-01-02 01:00:00', :name => 'Event name', :id => 3)
58
+ e4 = Osm::Event.new(:start => '2000-01-02 01:00:00', :name => 'Event name', :id => 4)
59
+ events = [e2, e4, e3, e1]
60
+
61
+ events.sort.should == [e1, e2, e3, e4]
62
+ (Osm::Event.new(:id => 1) <=> Osm::Event.new(:id => 1)).should == 0
63
+ end
54
64
 
55
- it "Create Event::Attendance" do
56
- data = {
57
- :member_id => 1,
58
- :grouping_id => 2,
59
- :row => 3,
60
- :columns => [],
61
- :event => Osm::Event.new(:id => 1, :section_id => 1, :name => 'Name', :columns => [])
62
- }
65
+ describe "Event::Attendance" do
66
+
67
+ it "Create" do
68
+ data = {
69
+ :member_id => 1,
70
+ :grouping_id => 2,
71
+ :row => 3,
72
+ :columns => [],
73
+ :event => Osm::Event.new(:id => 1, :section_id => 1, :name => 'Name', :columns => [])
74
+ }
63
75
 
64
- ea = Osm::Event::Attendance.new(data)
65
- ea.member_id.should == 1
66
- ea.grouping_id.should == 2
67
- ea.fields.should == {}
68
- ea.row.should == 3
69
- ea.valid?.should be_true
70
- end
76
+ ea = Osm::Event::Attendance.new(data)
77
+ ea.member_id.should == 1
78
+ ea.grouping_id.should == 2
79
+ ea.fields.should == {}
80
+ ea.row.should == 3
81
+ ea.valid?.should be_true
82
+ end
83
+
84
+ it "Sorts by event ID then row" do
85
+ ea1 = Osm::Event::Attendance.new(:event => Osm::Event.new(:id => 1), :row => 1)
86
+ ea2 = Osm::Event::Attendance.new(:event => Osm::Event.new(:id => 2), :row => 1)
87
+ ea3 = Osm::Event::Attendance.new(:event => Osm::Event.new(:id => 2), :row => 2)
88
+ event_attendances = [ea3, ea2, ea1]
71
89
 
90
+ event_attendances.sort.should == [ea1, ea2, ea3]
91
+ end
92
+
93
+ end
72
94
 
73
95
  describe "Using the API" do
74
96
 
@@ -17,25 +17,58 @@ describe "Flexi Record" do
17
17
  fr.valid?.should be_true
18
18
  end
19
19
 
20
- it "Create FlexiRecord::Column" do
21
- field = Osm::FlexiRecord::Column.new(
22
- :id => "f_1",
23
- :name => "Field Name",
24
- :editable => true,
25
- :flexi_record => Osm::FlexiRecord.new(),
26
- )
20
+ describe "FlexiRecord::Column" do
21
+
22
+ it "Create" do
23
+ field = Osm::FlexiRecord::Column.new(
24
+ :id => "f_1",
25
+ :name => "Field Name",
26
+ :editable => true,
27
+ :flexi_record => Osm::FlexiRecord.new(),
28
+ )
29
+
30
+ field.id.should == 'f_1'
31
+ field.name.should == 'Field Name'
32
+ field.editable.should be_true
33
+ field.valid?.should be_true
34
+ end
35
+
36
+ it "Sorts by flexirecord then id (system first then user)" do
37
+ frc1 = Osm::FlexiRecord::Column.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 1), :id => 'f_1')
38
+ frc2 = Osm::FlexiRecord::Column.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :id => 'a')
39
+ frc3 = Osm::FlexiRecord::Column.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :id => 'b')
40
+ frc4 = Osm::FlexiRecord::Column.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :id => 'f_1')
41
+ frc5 = Osm::FlexiRecord::Column.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :id => 'f_2')
42
+
43
+ columns = [frc3, frc2, frc1, frc5, frc4]
44
+ columns.sort.should == [frc1, frc2, frc3, frc4, frc5]
45
+ end
27
46
 
28
- field.id.should == 'f_1'
29
- field.name.should == 'Field Name'
30
- field.editable.should be_true
31
- field.valid?.should be_true
32
47
  end
33
48
 
34
- it "Create FlexiRecord::Data" do
35
- rd = Osm::FlexiRecord::Data.new(
36
- :member_id => 1,
37
- :grouping_id => 2,
38
- :fields => {
49
+
50
+ describe "FlexiRecord::Data" do
51
+
52
+ it "Create" do
53
+ rd = Osm::FlexiRecord::Data.new(
54
+ :member_id => 1,
55
+ :grouping_id => 2,
56
+ :fields => {
57
+ 'firstname' => 'First',
58
+ 'lastname' => 'Last',
59
+ 'dob' => Date.new(1899, 11, 30),
60
+ 'total' => 3,
61
+ 'completed' => nil,
62
+ 'age' => nil,
63
+ 'f_1' => 'a',
64
+ 'f_2' => 'b',
65
+ },
66
+ :flexi_record => Osm::FlexiRecord.new()
67
+ )
68
+
69
+ rd.member_id.should == 1
70
+ rd.grouping_id.should == 2
71
+ rd.fields.should == {
39
72
  'firstname' => 'First',
40
73
  'lastname' => 'Last',
41
74
  'dob' => Date.new(1899, 11, 30),
@@ -44,29 +77,27 @@ describe "Flexi Record" do
44
77
  'age' => nil,
45
78
  'f_1' => 'a',
46
79
  'f_2' => 'b',
47
- },
48
- :flexi_record => Osm::FlexiRecord.new()
49
- )
80
+ }
81
+ rd.valid?.should be_true
82
+ end
83
+
84
+ it "Sorts by flexirecord, grouping_id then member_id" do
85
+ frd1 = Osm::FlexiRecord::Data.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 1), :grouping_id => 1, :member_id => 1)
86
+ frd2 = Osm::FlexiRecord::Data.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :grouping_id => 1, :member_id => 1)
87
+ frd3 = Osm::FlexiRecord::Data.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :grouping_id => 2, :member_id => 1)
88
+ frd4 = Osm::FlexiRecord::Data.new(:flexi_record => Osm::FlexiRecord.new(:section_id => 2), :grouping_id => 2, :member_id => 2)
89
+
90
+ datas = [frd3, frd2, frd1, frd4]
91
+ datas.sort.should == [frd1, frd2, frd3, frd4]
92
+ end
50
93
 
51
- rd.member_id.should == 1
52
- rd.grouping_id.should == 2
53
- rd.fields.should == {
54
- 'firstname' => 'First',
55
- 'lastname' => 'Last',
56
- 'dob' => Date.new(1899, 11, 30),
57
- 'total' => 3,
58
- 'completed' => nil,
59
- 'age' => nil,
60
- 'f_1' => 'a',
61
- 'f_2' => 'b',
62
- }
63
- rd.valid?.should be_true
64
94
  end
65
95
 
66
- it "Sorts by name" do
67
- fr1 = Osm::FlexiRecord.new(:id => 3, :name => 'A')
68
- fr2 = Osm::FlexiRecord.new(:id => 2, :name => 'B')
69
- fr3 = Osm::FlexiRecord.new(:id => 1, :name => 'C')
96
+
97
+ it "Sorts by section ID then name" do
98
+ fr1 = Osm::FlexiRecord.new(:section_id => 1, :name => 'A')
99
+ fr2 = Osm::FlexiRecord.new(:section_id => 2, :name => 'B')
100
+ fr3 = Osm::FlexiRecord.new(:section_id => 2, :name => 'C')
70
101
  records = [fr2, fr1, fr3]
71
102
 
72
103
  records.sort.should == [fr1, fr2, fr3]
@@ -3,6 +3,15 @@ require 'spec_helper'
3
3
 
4
4
  describe "Grouping" do
5
5
 
6
+ it "Sorts by section_id then name" do
7
+ g1 = Osm::Grouping.new(:section_id => 1, :name => 'a')
8
+ g2 = Osm::Grouping.new(:section_id => 2, :name => 'a')
9
+ g3 = Osm::Grouping.new(:section_id => 2, :name => 'b')
10
+
11
+ data = [g3, g1, g2]
12
+ data.sort.should == [g1, g2, g3]
13
+ end
14
+
6
15
  describe "Using the API" do
7
16
 
8
17
  it "Get for section" do
@@ -76,6 +85,7 @@ describe "Grouping" do
76
85
 
77
86
  grouping.update(@api).should be_true
78
87
  end
88
+
79
89
  it "Update in OSM (failed)" do
80
90
  grouping = Osm::Grouping.new(
81
91
  :id => 1,
@@ -47,17 +47,30 @@ describe "Meeting" do
47
47
  end
48
48
 
49
49
 
50
- it "Create Meeting::Activity" do
51
- ea = Osm::Meeting::Activity.new(
52
- :activity_id => 2,
53
- :title => 'Activity Name',
54
- :notes => 'Notes',
55
- )
50
+ describe "Meeting::Activity" do
51
+
52
+ it "Create Meeting::Activity" do
53
+ ea = Osm::Meeting::Activity.new(
54
+ :activity_id => 2,
55
+ :title => 'Activity Name',
56
+ :notes => 'Notes',
57
+ )
58
+
59
+ ea.activity_id.should == 2
60
+ ea.title.should == 'Activity Name'
61
+ ea.notes.should == 'Notes'
62
+ ea.valid?.should be_true
63
+ end
64
+
65
+ it "Sorts by title then activity_id" do
66
+ a1 = Osm::Meeting::Activity.new(:title => 'a', :activity_id => 1)
67
+ a2 = Osm::Meeting::Activity.new(:title => 'b', :activity_id => 1)
68
+ a3 = Osm::Meeting::Activity.new(:title => 'b', :activity_id => 2)
69
+
70
+ data = [a2, a3, a1]
71
+ data.sort.should == [a1, a2, a3]
72
+ end
56
73
 
57
- ea.activity_id.should == 2
58
- ea.title.should == 'Activity Name'
59
- ea.notes.should == 'Notes'
60
- ea.valid?.should be_true
61
74
  end
62
75
 
63
76
 
@@ -113,6 +113,20 @@ describe "Member" do
113
113
  end
114
114
 
115
115
 
116
+ it "Sorts by section_id, grouping_id, grouping_leader (descending), last_name then first_name" do
117
+ m1 = Osm::Member.new(:section_id => 1, :grouping_id => 1, :grouping_leader => 1, :last_name => 'a', :first_name => 'a')
118
+ m2 = Osm::Member.new(:section_id => 2, :grouping_id => 1, :grouping_leader => 1, :last_name => 'a', :first_name => 'a')
119
+ m3 = Osm::Member.new(:section_id => 2, :grouping_id => 2, :grouping_leader => 1, :last_name => 'a', :first_name => 'a')
120
+ m4 = Osm::Member.new(:section_id => 2, :grouping_id => 2, :grouping_leader => 0, :last_name => 'a', :first_name => 'a')
121
+ m5 = Osm::Member.new(:section_id => 2, :grouping_id => 2, :grouping_leader => 0, :last_name => 'a', :first_name => 'a')
122
+ m6 = Osm::Member.new(:section_id => 2, :grouping_id => 2, :grouping_leader => 0, :last_name => 'b', :first_name => 'a')
123
+ m7 = Osm::Member.new(:section_id => 2, :grouping_id => 2, :grouping_leader => 0, :last_name => 'b', :first_name => 'b')
124
+
125
+ data = [m4, m2, m3, m1, m7, m6, m5]
126
+ data.sort.should == [m1, m2, m3, m4, m5, m6, m7]
127
+ end
128
+
129
+
116
130
  describe "Using the API" do
117
131
 
118
132
  it "Create from API data" do
@@ -5,8 +5,8 @@ require 'spec_helper'
5
5
  describe "Model" do
6
6
 
7
7
  class ModelTester < Osm::Model
8
- attribute :test_attribute
9
- attr_accessible :test_attribute
8
+ attribute :id
9
+ attr_accessible :id
10
10
 
11
11
  def self.test_get_config
12
12
  {
@@ -120,15 +120,63 @@ describe "Model" do
120
120
 
121
121
 
122
122
  describe "Track attribute changes" do
123
- test = ModelTester.new(:test_attribute => 1)
124
- test.test_attribute.should == 1
123
+ test = ModelTester.new(:id => 1)
124
+ test.id.should == 1
125
125
  test.changed_attributes.should == []
126
126
 
127
- test.test_attribute = 2
128
- test.changed_attributes.should == ['test_attribute']
127
+ test.id = 2
128
+ test.changed_attributes.should == ['id']
129
129
 
130
130
  test.reset_changed_attributes
131
131
  test.changed_attributes.should == []
132
132
  end
133
133
 
134
+
135
+ describe "Comparisons" do
136
+
137
+ before :each do
138
+ @mt1 = ModelTester.new(:id => 1)
139
+ @mt2 = ModelTester.new(:id => 2)
140
+ @mt3 = ModelTester.new(:id => 3)
141
+ @mt2a = ModelTester.new(:id => 2)
142
+ end
143
+
144
+ it "<=>" do
145
+ (@mt1 <=> @mt2).should == -1
146
+ (@mt2 <=> @mt1).should == 1
147
+ (@mt2 <=> @mt2a).should == 0
148
+ end
149
+
150
+ it ">" do
151
+ (@mt1 > @mt2).should be_false
152
+ (@mt2 > @mt1).should be_true
153
+ (@mt2 > @mt2a).should be_false
154
+ end
155
+
156
+ it ">=" do
157
+ (@mt1 >= @mt2).should be_false
158
+ (@mt2 >= @mt1).should be_true
159
+ (@mt2 >= @mt2a).should be_true
160
+ end
161
+
162
+ it "<" do
163
+ (@mt1 < @mt2).should be_true
164
+ (@mt2 < @mt1).should be_false
165
+ (@mt2 < @mt2a).should be_false
166
+ end
167
+
168
+ it "<=" do
169
+ (@mt1 <= @mt2).should be_true
170
+ (@mt2 <= @mt1).should be_false
171
+ (@mt2 <= @mt2a).should be_true
172
+ end
173
+
174
+ it "between" do
175
+ @mt2.between?(@mt1, @mt3).should be_true
176
+ @mt1.between?(@mt1, @mt3).should be_false
177
+ @mt3.between?(@mt1, @mt3).should be_false
178
+ end
179
+
180
+ end
181
+
134
182
  end
@@ -18,7 +18,16 @@ describe "Register" do
18
18
  field.valid?.should be_true
19
19
  end
20
20
 
21
- it "Create Data" do
21
+ it "Sorts Field by id" do
22
+ a1 = Osm::Register::Field.new(:id => 'a')
23
+ a2 = Osm::Register::Field.new(:id => 'a')
24
+
25
+ data = [a2, a1]
26
+ data.sort.should == [a1, a2]
27
+ end
28
+
29
+
30
+ it "Create Attendance" do
22
31
  rd = Osm::Register::Attendance.new(
23
32
  :member_id => '1',
24
33
  :first_name => 'A',
@@ -45,6 +54,17 @@ describe "Register" do
45
54
  rd.valid?.should be_true
46
55
  end
47
56
 
57
+ it "Sorts Attendance by section_id, grouping_id, last_name then first_name" do
58
+ d1 = Osm::Register::Attendance.new(:section_id => 1, :grouping_id => 1, :last_name => 'a', :first_name => 'a')
59
+ d2 = Osm::Register::Attendance.new(:section_id => 2, :grouping_id => 1, :last_name => 'a', :first_name => 'a')
60
+ d3 = Osm::Register::Attendance.new(:section_id => 2, :grouping_id => 2, :last_name => 'a', :first_name => 'a')
61
+ d4 = Osm::Register::Attendance.new(:section_id => 2, :grouping_id => 2, :last_name => 'b', :first_name => 'a')
62
+ d5 = Osm::Register::Attendance.new(:section_id => 2, :grouping_id => 2, :last_name => 'b', :first_name => 'b')
63
+
64
+ data = [d4, d3, d5, d2, d1]
65
+ data.sort.should == [d1, d2, d3, d4, d5]
66
+ end
67
+
48
68
 
49
69
  describe "Using the API" do
50
70
 
@@ -228,12 +228,14 @@ describe "Section" do
228
228
  end
229
229
 
230
230
 
231
- it "Sorts by Group Name then section type (age order)" do
232
- section1 = Osm::Section.new(@attributes.merge(:group_id => 1, :group_name => '1st Somewhere', :type => :beavers))
233
- section2 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :beavers))
234
- section3 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :cubs))
235
-
236
- [section2, section3, section1].sort.should == [section1, section2, section3]
231
+ it "Sorts by Group Name, section type (age order) then name" do
232
+ section1 = Osm::Section.new(@attributes.merge(:group_id => 1, :group_name => '1st Somewhere', :type => :beavers, :name => 'a'))
233
+ section2 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :beavers, :name => 'a'))
234
+ section3 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :cubs, :name => 'a'))
235
+ section4 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :cubs, :name => 'b'))
236
+
237
+ data = [section2, section4, section3, section1]
238
+ data.sort.should == [section1, section2, section3, section4]
237
239
  end
238
240
 
239
241
 
@@ -37,7 +37,7 @@ describe "Term" do
37
37
  term.should_not == Osm::Term.new(@attributes.merge(:id => 3))
38
38
  end
39
39
 
40
- it "Sorts by Section ID, Start date and th Term ID" do
40
+ it "Sorts by Section ID, Start date and then Term ID" do
41
41
  term1 = Osm::Term.new(@attributes.merge(:section_id => 1, :term => 11, :start => (Date.today - 60), :finish => (Date.today - 1)))
42
42
  term2 = Osm::Term.new(@attributes.merge(:section_id => 1, :term => 12, :start => (Date.today - 0), :finish => (Date.today + 0)))
43
43
  term3 = Osm::Term.new(@attributes.merge(:section_id => 1, :term => 13, :start => (Date.today + 1), :finish => (Date.today + 60)))
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Osm
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
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.2.0
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000Z
12
+ date: 2013-02-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &88142390 !ruby/object:Gem::Requirement
16
+ requirement: &86025430 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *88142390
24
+ version_requirements: *86025430
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &88141970 !ruby/object:Gem::Requirement
27
+ requirement: &86024870 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *88141970
35
+ version_requirements: *86024870
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: active_attr
38
- requirement: &88141440 !ruby/object:Gem::Requirement
38
+ requirement: &86006950 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.6'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *88141440
46
+ version_requirements: *86006950
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activemodel
49
- requirement: &88141060 !ruby/object:Gem::Requirement
49
+ requirement: &86006710 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.2'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *88141060
57
+ version_requirements: *86006710
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &88140610 !ruby/object:Gem::Requirement
60
+ requirement: &86006480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '10.0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *88140610
68
+ version_requirements: *86006480
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &88122850 !ruby/object:Gem::Requirement
71
+ requirement: &86006220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '2.11'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *88122850
79
+ version_requirements: *86006220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: fakeweb
82
- requirement: &88122440 !ruby/object:Gem::Requirement
82
+ requirement: &86005980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '1.3'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *88122440
90
+ version_requirements: *86005980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-rspec
93
- requirement: &88122180 !ruby/object:Gem::Requirement
93
+ requirement: &86005750 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '2.4'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *88122180
101
+ version_requirements: *86005750
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rb-inotify
104
- requirement: &88121560 !ruby/object:Gem::Requirement
104
+ requirement: &86005510 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 0.8.8
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *88121560
112
+ version_requirements: *86005510
113
113
  description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
114
114
  to retrieve and save data.
115
115
  email: