osm 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,199 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
4
+
5
+
6
+ describe "Section" do
7
+
8
+ class DummyRole
9
+ attr_reader :id
10
+ def initialize(id)
11
+ @id = id
12
+ end
13
+ def <=>(another)
14
+ @id <=> another.try(:id)
15
+ end
16
+ end
17
+
18
+
19
+
20
+ it "Create" do
21
+ data = {
22
+ 'subscription_level' => '3',
23
+ 'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
24
+ 'sectionType' => 'cubs',
25
+ 'numscouts' => 10,
26
+ 'hasUsedBadgeRecords' => '1',
27
+ 'hasProgramme' => true,
28
+ 'wizard' => 'False',
29
+ 'columnNames' => {},
30
+ 'fields' => {},
31
+ 'intouch' => {},
32
+ 'mobFields' => {},
33
+ 'extraRecords' => [],
34
+ }
35
+ role = DummyRole.new(1)
36
+ section = Osm::Section.new(1, 'Name', data, role)
37
+
38
+ section.id.should == 1
39
+ section.name.should == 'Name'
40
+ section.subscription_level.should == :gold
41
+ section.subscription_expires.should == Date.today + 60
42
+ section.type.should == :cubs
43
+ section.num_scouts.should == 10
44
+ section.has_badge_records.should == true
45
+ section.has_programme.should == true
46
+ section.wizard.should == false
47
+ section.column_names.should == {}
48
+ section.fields.should == {}
49
+ section.intouch_fields.should == {}
50
+ section.mobile_fields.should == {}
51
+ section.extra_records.should == []
52
+ section.role.should == role
53
+ end
54
+
55
+ it "Create has sensible defaults" do
56
+ section = Osm::Section.new(1, 'Name', {}, nil)
57
+
58
+ section.subscription_level.should == :unknown
59
+ section.subscription_expires.should == nil
60
+ section.type.should == :unknown
61
+ section.num_scouts.should == nil
62
+ section.column_names.should == {}
63
+ section.fields.should == {}
64
+ section.intouch_fields.should == {}
65
+ section.mobile_fields.should == {}
66
+ section.extra_records.should == []
67
+ end
68
+
69
+
70
+ it "Compares two matching sections" do
71
+ data = {
72
+ 'subscription_level' => '3',
73
+ 'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
74
+ 'sectionType' => 'cubs',
75
+ 'numscouts' => '10',
76
+ 'hasUsedBadgeRecords' => '1',
77
+ 'hasProgramme' => true,
78
+ 'wizard' => 'False',
79
+ 'columnNames' => {},
80
+ 'fields' => {},
81
+ 'intouch' => {},
82
+ 'mobFields' => {},
83
+ 'extraRecords' => [],
84
+ }
85
+ role = DummyRole.new(1)
86
+ section1 = Osm::Section.new(1, 'Name', data, role)
87
+ section2 = section1.clone
88
+
89
+ section1.should == section2
90
+ end
91
+
92
+ it "Compares two non-matching sections" do
93
+ data = {
94
+ 'subscription_level' => '3',
95
+ 'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
96
+ 'sectionType' => 'cubs',
97
+ 'numscouts' => '10',
98
+ 'hasUsedBadgeRecords' => '1',
99
+ 'hasProgramme' => true,
100
+ 'wizard' => 'False',
101
+ 'columnNames' => {},
102
+ 'fields' => {},
103
+ 'intouch' => {},
104
+ 'mobFields' => {},
105
+ 'extraRecords' => [],
106
+ }
107
+ role = DummyRole.new(1)
108
+ section1 = Osm::Section.new(1, 'Name', data, role)
109
+ section2 = Osm::Section.new(2, 'Name', data, role)
110
+
111
+ section1.should_not == section2
112
+ end
113
+
114
+
115
+ it "Sorts by role" do
116
+ data = {
117
+ 'subscription_level' => '3',
118
+ 'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
119
+ 'sectionType' => 'cubs',
120
+ 'numscouts' => '10',
121
+ 'hasUsedBadgeRecords' => '1',
122
+ 'hasProgramme' => true,
123
+ 'wizard' => 'False',
124
+ 'columnNames' => {},
125
+ 'fields' => {},
126
+ 'intouch' => {},
127
+ 'mobFields' => {},
128
+ 'extraRecords' => [],
129
+ }
130
+ section1 = Osm::Section.new(1, 'Name', data, DummyRole.new(1))
131
+ section2 = Osm::Section.new(1, 'Name', data, DummyRole.new(2))
132
+
133
+ [section2, section1].sort.should == [section1, section2]
134
+ end
135
+
136
+
137
+ it "Correctly works out the section type" do
138
+ data = {
139
+ 'subscription_level' => '3',
140
+ 'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
141
+ 'numscouts' => '10',
142
+ 'hasUsedBadgeRecords' => '1',
143
+ 'hasProgramme' => true,
144
+ 'wizard' => 'False',
145
+ 'columnNames' => {},
146
+ 'fields' => {},
147
+ 'intouch' => {},
148
+ 'mobFields' => {},
149
+ 'extraRecords' => [],
150
+ }
151
+
152
+ unknown = Osm::Section.new(1, 'Name', data, DummyRole.new(1))
153
+ beavers = Osm::Section.new(2, 'Name', data.merge('sectionType' => 'beavers'), DummyRole.new(2))
154
+ cubs = Osm::Section.new(3, 'Name', data.merge('sectionType' => 'cubs'), DummyRole.new(3))
155
+ scouts = Osm::Section.new(4, 'Name', data.merge('sectionType' => 'scouts'), DummyRole.new(4))
156
+ explorers = Osm::Section.new(5, 'Name', data.merge('sectionType' => 'explorers'), DummyRole.new(5))
157
+ adults = Osm::Section.new(6, 'Name', data.merge('sectionType' => 'adults'), DummyRole.new(6))
158
+ waiting = Osm::Section.new(7, 'Name', data.merge('sectionType' => 'waiting'), DummyRole.new(7))
159
+
160
+ {:beavers => beavers, :cubs => cubs, :scouts => scouts, :explorers => explorers, :adults => adults, :waiting => waiting, :unknwoon => unknown}.each do |section_type, section|
161
+ [:beavers, :cubs, :scouts, :explorers, :adults, :waiting].each do |type|
162
+ section.send("#{type.to_s}?").should == (section_type == type)
163
+ end
164
+ end
165
+ end
166
+
167
+
168
+ it "Correctly works out if the section is a youth section" do
169
+ data = {
170
+ 'subscription_level' => '3',
171
+ 'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
172
+ 'numscouts' => '10',
173
+ 'hasUsedBadgeRecords' => '1',
174
+ 'hasProgramme' => true,
175
+ 'wizard' => 'False',
176
+ 'columnNames' => {},
177
+ 'fields' => {},
178
+ 'intouch' => {},
179
+ 'mobFields' => {},
180
+ 'extraRecords' => [],
181
+ }
182
+
183
+ unknown = Osm::Section.new(1, 'Name', data, DummyRole.new(1))
184
+ beavers = Osm::Section.new(2, 'Name', data.merge('sectionType' => 'beavers'), DummyRole.new(2))
185
+ cubs = Osm::Section.new(3, 'Name', data.merge('sectionType' => 'cubs'), DummyRole.new(3))
186
+ scouts = Osm::Section.new(4, 'Name', data.merge('sectionType' => 'scouts'), DummyRole.new(4))
187
+ explorers = Osm::Section.new(5, 'Name', data.merge('sectionType' => 'explorers'), DummyRole.new(5))
188
+ adults = Osm::Section.new(6, 'Name', data.merge('sectionType' => 'adults'), DummyRole.new(6))
189
+ waiting = Osm::Section.new(7, 'Name', data.merge('sectionType' => 'waiting'), DummyRole.new(7))
190
+
191
+ [beavers, cubs, scouts, explorers].each do |section|
192
+ section.youth_section?.should == true
193
+ end
194
+ [adults, waiting, unknown].each do |section|
195
+ section.youth_section?.should == false
196
+ end
197
+ end
198
+
199
+ end
@@ -0,0 +1,162 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
4
+
5
+ describe "Term" do
6
+
7
+ it "Create" do
8
+ data = {
9
+ 'termid' => '1',
10
+ 'sectionid' => '2',
11
+ 'name' => 'Term name',
12
+ 'startdate' => '2001-01-01',
13
+ 'enddate' => '2001-03-31'
14
+ }
15
+ term = Osm::Term.new(data)
16
+
17
+ term.id.should == 1
18
+ term.section_id.should == 2
19
+ term.name.should == 'Term name'
20
+ term.start.should == Date.new(2001, 1, 1)
21
+ term.end.should == Date.new(2001, 3, 31)
22
+ end
23
+
24
+
25
+ it "Compares two matching terms" do
26
+ data = {
27
+ 'termid' => '1',
28
+ 'sectionid' => '2',
29
+ 'name' => 'Term name',
30
+ 'startdate' => '2001-01-01',
31
+ 'enddate' => '2001-03-31'
32
+ }
33
+ term1 = Osm::Term.new(data)
34
+ term2 = Osm::Term.new(data)
35
+ term1.should == term2
36
+ end
37
+
38
+ it "Compares two non-matching terms" do
39
+ data = {
40
+ 'termid' => '1',
41
+ 'sectionid' => '2',
42
+ 'name' => 'Term name',
43
+ 'startdate' => '2001-01-01',
44
+ 'enddate' => '2001-03-31'
45
+ }
46
+ term = Osm::Term.new(data)
47
+
48
+ term.should_not == Osm::Term.new(data.merge('termid' => '3'))
49
+ end
50
+
51
+
52
+ it "Sorts by Section ID, Start date and then Term ID" do
53
+ data = {
54
+ 'name' => 'Term name',
55
+ }
56
+ term1 = Osm::Term.new(data.merge('sectionid' => '1', 'termid' => '11', 'startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
57
+ term2 = Osm::Term.new(data.merge('sectionid' => '1', 'termid' => '12', 'startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
58
+ term3 = Osm::Term.new(data.merge('sectionid' => '1', 'termid' => '13', 'startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
59
+ term4 = Osm::Term.new(data.merge('sectionid' => '2', 'termid' => '1', 'startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
60
+ term5 = Osm::Term.new(data.merge('sectionid' => '2', 'termid' => '2', 'startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
61
+
62
+ data = [term5, term3, term2, term4, term1]
63
+ data.sort.should == [term1, term2, term3, term4, term5]
64
+ end
65
+
66
+
67
+ it "Works out if it is completly before a date" do
68
+ data = {
69
+ 'termid' => '1',
70
+ 'sectionid' => '2',
71
+ 'name' => 'Term name',
72
+ }
73
+ term1 = Osm::Term.new(data.merge('startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
74
+ term2 = Osm::Term.new(data.merge('startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
75
+ term3 = Osm::Term.new(data.merge('startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
76
+
77
+ term1.before?(Date.today).should == true
78
+ term2.before?(Date.today).should == false
79
+ term3.before?(Date.today).should == false
80
+ end
81
+
82
+
83
+ it "Works out if it is completly after a date" do
84
+ data = {
85
+ 'termid' => '1',
86
+ 'sectionid' => '2',
87
+ 'name' => 'Term name',
88
+ }
89
+ term1 = Osm::Term.new(data.merge('startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
90
+ term2 = Osm::Term.new(data.merge('startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
91
+ term3 = Osm::Term.new(data.merge('startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
92
+
93
+ term1.after?(Date.today).should == false
94
+ term2.after?(Date.today).should == false
95
+ term3.after?(Date.today).should == true
96
+ end
97
+
98
+
99
+ it "Works out if it has passed" do
100
+ data = {
101
+ 'termid' => '1',
102
+ 'sectionid' => '2',
103
+ 'name' => 'Term name',
104
+ }
105
+ term1 = Osm::Term.new(data.merge('startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
106
+ term2 = Osm::Term.new(data.merge('startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
107
+ term3 = Osm::Term.new(data.merge('startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
108
+
109
+ term1.past?().should == true
110
+ term2.past?().should == false
111
+ term3.past?().should == false
112
+ end
113
+
114
+
115
+ it "Works out if it is in the future" do
116
+ data = {
117
+ 'termid' => '1',
118
+ 'sectionid' => '2',
119
+ 'name' => 'Term name',
120
+ }
121
+ term1 = Osm::Term.new(data.merge('startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
122
+ term2 = Osm::Term.new(data.merge('startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
123
+ term3 = Osm::Term.new(data.merge('startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
124
+
125
+ term1.future?().should == false
126
+ term2.future?().should == false
127
+ term3.future?().should == true
128
+ end
129
+
130
+
131
+ it "Works out if it is the current term" do
132
+ data = {
133
+ 'termid' => '1',
134
+ 'sectionid' => '2',
135
+ 'name' => 'Term name',
136
+ }
137
+ term1 = Osm::Term.new(data.merge('startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
138
+ term2 = Osm::Term.new(data.merge('startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
139
+ term3 = Osm::Term.new(data.merge('startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
140
+
141
+ term1.current?().should == false
142
+ term2.current?().should == true
143
+ term3.current?().should == false
144
+ end
145
+
146
+
147
+ it "Works out if it contains a date" do
148
+ data = {
149
+ 'termid' => '1',
150
+ 'sectionid' => '2',
151
+ 'name' => 'Term name',
152
+ }
153
+ term1 = Osm::Term.new(data.merge('startdate' => (Date.today - 60).strftime('%Y-%m-%d'), 'enddate' => (Date.today - 1).strftime('%Y-%m-%d')))
154
+ term2 = Osm::Term.new(data.merge('startdate' => (Date.today - 0).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 0).strftime('%Y-%m-%d')))
155
+ term3 = Osm::Term.new(data.merge('startdate' => (Date.today + 1).strftime('%Y-%m-%d'), 'enddate' => (Date.today + 60).strftime('%Y-%m-%d')))
156
+
157
+ term1.contains_date?(Date.today).should == false
158
+ term2.contains_date?(Date.today).should == true
159
+ term3.contains_date?(Date.today).should == false
160
+ end
161
+
162
+ end
@@ -0,0 +1,58 @@
1
+ require 'fakeweb'
2
+ require 'httparty'
3
+ require 'active_support'
4
+
5
+ require 'osm'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+
10
+ RSpec.configure do |config|
11
+ # == Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+ config.mock_with :rspec
19
+
20
+ config.before(:each) do
21
+ FakeWeb.clean_registry
22
+ Rails.cache.clear
23
+ end
24
+ end
25
+
26
+
27
+ module Rails
28
+ def self.cache
29
+ @cache ||= Cache.new
30
+ end
31
+ def self.env
32
+ Env.new
33
+ end
34
+
35
+ class Env
36
+ def development?
37
+ false
38
+ end
39
+ end
40
+
41
+ class Cache
42
+ def initialize
43
+ @cache = {}
44
+ end
45
+ def write(key, data, options={})
46
+ @cache[key] = data
47
+ end
48
+ def read(key)
49
+ @cache[key]
50
+ end
51
+ def exist?(key)
52
+ @cache.include?(key)
53
+ end
54
+ def clear
55
+ @cache = {}
56
+ end
57
+ end
58
+ end
data/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Osm
2
+ VERSION = "0.0.1.alpha"
3
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Robert Gauld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-31 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &86907540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *86907540
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &86907280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *86907280
36
+ - !ruby/object:Gem::Dependency
37
+ name: httparty
38
+ requirement: &86907050 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *86907050
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &86906700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *86906700
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &86906390 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *86906390
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakeweb
71
+ requirement: &86906030 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *86906030
80
+ description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
81
+ to retrieve and save data.
82
+ email:
83
+ - robert@robertgauld.co.uk
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - .rspec
90
+ - .travis.yml
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.rdoc
95
+ - README.md
96
+ - Rakefile
97
+ - lib/osm.rb
98
+ - lib/osm/activity.rb
99
+ - lib/osm/api.rb
100
+ - lib/osm/api_access.rb
101
+ - lib/osm/due_badges.rb
102
+ - lib/osm/event.rb
103
+ - lib/osm/grouping.rb
104
+ - lib/osm/member.rb
105
+ - lib/osm/programme_activity.rb
106
+ - lib/osm/programme_item.rb
107
+ - lib/osm/role.rb
108
+ - lib/osm/section.rb
109
+ - lib/osm/term.rb
110
+ - osm.gemspec
111
+ - spec/osm/activity_spec.rb
112
+ - spec/osm/api_access_spec.rb
113
+ - spec/osm/api_spec.rb
114
+ - spec/osm/api_strangeness_spec.rb
115
+ - spec/osm/due_badges_spec.rb
116
+ - spec/osm/event_spec.rb
117
+ - spec/osm/grouping_spec.rb
118
+ - spec/osm/member_spec.rb
119
+ - spec/osm/osm_spec.rb
120
+ - spec/osm/programme_activity_spec.rb
121
+ - spec/osm/programme_item_spec.rb
122
+ - spec/osm/role_spec.rb
123
+ - spec/osm/section_spec.rb
124
+ - spec/osm/term_spec.rb
125
+ - spec/spec_helper.rb
126
+ - version.rb
127
+ homepage: ''
128
+ licenses: []
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>'
143
+ - !ruby/object:Gem::Version
144
+ version: 1.3.1
145
+ requirements: []
146
+ rubyforge_project: osm
147
+ rubygems_version: 1.8.10
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Use the Online Scout Manager API
151
+ test_files: []
152
+ has_rdoc: