osm 0.0.26 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +57 -0
- data/README.md +13 -7
- data/lib/osm.rb +47 -22
- data/lib/osm/activity.rb +52 -57
- data/lib/osm/api.rb +115 -1031
- data/lib/osm/api_access.rb +73 -36
- data/lib/osm/due_badges.rb +27 -12
- data/lib/osm/evening.rb +118 -55
- data/lib/osm/event.rb +275 -17
- data/lib/osm/flexi_record.rb +131 -0
- data/lib/osm/grouping.rb +37 -15
- data/lib/osm/member.rb +100 -41
- data/lib/osm/model.rb +95 -0
- data/lib/osm/register.rb +177 -0
- data/lib/osm/section.rb +163 -71
- data/lib/osm/term.rb +135 -21
- data/spec/osm/activity_spec.rb +7 -4
- data/spec/osm/api_access_spec.rb +44 -36
- data/spec/osm/api_spec.rb +32 -1147
- data/spec/osm/due_badges_spec.rb +8 -1
- data/spec/osm/evening_spec.rb +119 -54
- data/spec/osm/event_spec.rb +363 -13
- data/spec/osm/flexi_record_spec.rb +128 -0
- data/spec/osm/grouping_spec.rb +9 -5
- data/spec/osm/member_spec.rb +111 -36
- data/spec/osm/model_spec.rb +140 -0
- data/spec/osm/osm_spec.rb +7 -31
- data/spec/osm/register_spec.rb +103 -0
- data/spec/osm/section_spec.rb +208 -92
- data/spec/osm/term_spec.rb +164 -28
- data/spec/spec_helper.rb +22 -0
- data/version.rb +1 -1
- metadata +22 -29
- data/lib/osm/event_attendance.rb +0 -55
- data/lib/osm/flexi_record_data.rb +0 -51
- data/lib/osm/flexi_record_field.rb +0 -42
- data/lib/osm/register_data.rb +0 -64
- data/lib/osm/register_field.rb +0 -42
- data/lib/osm/role.rb +0 -133
- data/spec/osm/api_strangeness_spec.rb +0 -83
- data/spec/osm/event_attendance_spec.rb +0 -34
- data/spec/osm/flexi_record_data_spec.rb +0 -40
- data/spec/osm/flexi_record_field_spec.rb +0 -23
- data/spec/osm/register_data_spec.rb +0 -35
- data/spec/osm/register_field_spec.rb +0 -24
- data/spec/osm/role_spec.rb +0 -118
data/spec/osm/osm_spec.rb
CHANGED
@@ -12,36 +12,6 @@ describe "Online Scout Manager" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
|
15
|
-
describe "find current term ID" do
|
16
|
-
it "Returns the current term for the section from all terms returned by OSM" do
|
17
|
-
Osm::Api.configure({:api_id=>'1234', :api_token=>'12345678', :api_name=>'API', :api_site=>:scout})
|
18
|
-
api = Osm::Api.new('2345', 'abcd')
|
19
|
-
|
20
|
-
body = '{"9":['
|
21
|
-
body += '{"termid":"1","name":"Term 1","sectionid":"9","startdate":"' + (Date.today - 90).strftime('%Y-%m-%d') + '","enddate":"' + (Date.today - 31).strftime('%Y-%m-%d') + '"},'
|
22
|
-
body += '{"termid":"2","name":"Term 2","sectionid":"9","startdate":"' + (Date.today - 30).strftime('%Y-%m-%d') + '","enddate":"' + (Date.today + 30).strftime('%Y-%m-%d') + '"},'
|
23
|
-
body += '{"termid":"3","name":"Term 3","sectionid":"9","startdate":"' + (Date.today + 31).strftime('%Y-%m-%d') + '","enddate":"' + (Date.today + 90).strftime('%Y-%m-%d') + '"}'
|
24
|
-
body += ']}'
|
25
|
-
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getTerms", :body => body)
|
26
|
-
|
27
|
-
Osm::find_current_term_id(api, 9).should == 2
|
28
|
-
end
|
29
|
-
|
30
|
-
it "Raises an error if there is no current term" do
|
31
|
-
Osm::Api.configure({:api_id=>'1234', :api_token=>'12345678', :api_name=>'API', :api_site=>:scout})
|
32
|
-
api = Osm::Api.new('2345', 'abcd')
|
33
|
-
section_id = 9
|
34
|
-
|
35
|
-
body = '{"9":['
|
36
|
-
body += '{"termid":"1","name":"Term 1","sectionid":"9","startdate":"' + (Date.today + 31).strftime('%Y-%m-%d') + '","enddate":"' + (Date.today + 90).strftime('%Y-%m-%d') + '"}'
|
37
|
-
body += ']}'
|
38
|
-
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getTerms", :body => body)
|
39
|
-
|
40
|
-
expect{ Osm::find_current_term_id(api, section_id) }.to raise_error(Osm::Error)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
15
|
describe "Make a DateTime" do
|
46
16
|
it "is given a date and a time" do
|
47
17
|
Osm::make_datetime('2001-02-03', '04:05:06').should == DateTime.new(2001, 02, 03, 04, 05, 06)
|
@@ -75,8 +45,14 @@ describe "Online Scout Manager" do
|
|
75
45
|
end
|
76
46
|
|
77
47
|
it "is given an invalid date string" do
|
78
|
-
Osm::parse_date('No date here!').should
|
48
|
+
Osm::parse_date('No date here!').should be_nil
|
79
49
|
end
|
50
|
+
|
51
|
+
it "is given a human date" do
|
52
|
+
Osm::parse_date('03/02/2001').should == Date.new(2001, 02, 03)
|
53
|
+
Osm::parse_date('3/2/2001').should == Date.new(2001, 02, 03)
|
54
|
+
end
|
55
|
+
|
80
56
|
end
|
81
57
|
|
82
58
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
|
6
|
+
describe "Register" do
|
7
|
+
|
8
|
+
it "Create Field" do
|
9
|
+
field = Osm::Register::Field.new(
|
10
|
+
:name => 'Human name',
|
11
|
+
:id => 'machine_name',
|
12
|
+
:tooltip => 'Tooltip'
|
13
|
+
)
|
14
|
+
|
15
|
+
field.id.should == 'machine_name'
|
16
|
+
field.name.should == 'Human name'
|
17
|
+
field.tooltip.should == 'Tooltip'
|
18
|
+
field.valid?.should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "Create Data" do
|
22
|
+
rd = Osm::Register::Attendance.new(
|
23
|
+
:member_id => '1',
|
24
|
+
:first_name => 'A',
|
25
|
+
:last_name => 'B',
|
26
|
+
:section_id => '2',
|
27
|
+
:grouping_id => '3',
|
28
|
+
:total => 4,
|
29
|
+
:attendance => {
|
30
|
+
Date.new(2012, 1, 10) => 'Yes',
|
31
|
+
Date.new(2012, 1, 24) => 'No',
|
32
|
+
}
|
33
|
+
)
|
34
|
+
|
35
|
+
rd.member_id.should == 1
|
36
|
+
rd.section_id.should == 2
|
37
|
+
rd.grouping_id.should == 3
|
38
|
+
rd.first_name.should == 'A'
|
39
|
+
rd.last_name.should == 'B'
|
40
|
+
rd.total.should == 4
|
41
|
+
rd.attendance.should == {
|
42
|
+
Date.new(2012, 01, 10) => 'Yes',
|
43
|
+
Date.new(2012, 01, 24) => 'No'
|
44
|
+
}
|
45
|
+
rd.valid?.should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "Using the API" do
|
50
|
+
|
51
|
+
it "Fetch the register structure for a section" do
|
52
|
+
data = [
|
53
|
+
{"rows" => [{"name"=>"First name","field"=>"firstname","width"=>"100px"},{"name"=>"Last name","field"=>"lastname","width"=>"100px"},{"name"=>"Total","field"=>"total","width"=>"60px"}],"noscroll"=>true},
|
54
|
+
{"rows" => []}
|
55
|
+
]
|
56
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/users.php?action=registerStructure§ionid=1&termid=2", :body => data.to_json)
|
57
|
+
|
58
|
+
register_structure = Osm::Register.get_structure(@api, 1, 2)
|
59
|
+
register_structure.is_a?(Array).should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "Fetch the register data for a section" do
|
63
|
+
data = {
|
64
|
+
'identifier' => 'scoutid',
|
65
|
+
'label' => "name",
|
66
|
+
'items' => []
|
67
|
+
}
|
68
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/users.php?action=register§ionid=1&termid=2", :body => data.to_json)
|
69
|
+
|
70
|
+
register = Osm::Register.get_attendance(@api, 1, 2)
|
71
|
+
register.is_a?(Array).should be_true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "Update register attendance" do
|
75
|
+
url = 'https://www.onlinescoutmanager.co.uk/users.php?action=registerUpdate§ionid=1&termid=2'
|
76
|
+
post_data = {
|
77
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
78
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
79
|
+
'userid' => 'user_id',
|
80
|
+
'secret' => 'secret',
|
81
|
+
'scouts' => '["3"]',
|
82
|
+
'selectedDate' => '2000-01-02',
|
83
|
+
'present' => 'Yes',
|
84
|
+
'section' => :cubs,
|
85
|
+
'sectionid' => 1,
|
86
|
+
'completedBadges' => '[{"a":"A"},{"b":"B"}]'
|
87
|
+
}
|
88
|
+
|
89
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'[]'}) }
|
90
|
+
Osm::Register.update_attendance({
|
91
|
+
:api => @api,
|
92
|
+
:section => Osm::Section.new(:id=>1, :type=>:cubs),
|
93
|
+
:term => 2,
|
94
|
+
:evening => Date.new(2000, 1, 2),
|
95
|
+
:attendance => 'Yes',
|
96
|
+
:members => 3,
|
97
|
+
:completed_badge_requirements => [{'a'=>'A'}, {'b'=>'B'}]
|
98
|
+
}).should be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/spec/osm/section_spec.rb
CHANGED
@@ -5,83 +5,46 @@ require 'date'
|
|
5
5
|
|
6
6
|
describe "Section" do
|
7
7
|
|
8
|
-
class DummyRole
|
9
|
-
attr_reader :id
|
10
|
-
def initialize(id)
|
11
|
-
@id = id
|
12
|
-
end
|
13
|
-
def <=>(another)
|
14
|
-
@id <=> another.id
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
8
|
before :each do
|
20
9
|
@attributes = {
|
21
10
|
:id => 1,
|
22
11
|
:name => 'Name',
|
23
12
|
:subscription_level => :silver,
|
24
13
|
:subscription_expires => (Date.today + 60).strftime('%Y-%m-%d'),
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:hasUsedBadgeRecords => true,
|
28
|
-
:hasProgramme => true,
|
14
|
+
:type => :cubs,
|
15
|
+
:num_scouts => 10,
|
29
16
|
:wizard => false,
|
30
|
-
:
|
31
|
-
:fields => {},
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
17
|
+
:column_names => {:column_names => 'names'},
|
18
|
+
:fields => {:fields => true},
|
19
|
+
:intouch_fields => {:intouch_fields => true},
|
20
|
+
:mobile_fields => {:mobile_fields => true},
|
21
|
+
:flexi_records => [],
|
22
|
+
:group_id => 3,
|
23
|
+
:group_name => '3rd Somewhere'
|
36
24
|
}
|
37
25
|
end
|
38
26
|
|
39
27
|
|
40
|
-
it "Create
|
41
|
-
|
42
|
-
'subscription_level' => '3',
|
43
|
-
'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
|
44
|
-
'sectionType' => 'cubs',
|
45
|
-
'numscouts' => 10,
|
46
|
-
'columnNames' => {},
|
47
|
-
'fields' => {},
|
48
|
-
'intouch' => {},
|
49
|
-
'mobFields' => {},
|
50
|
-
'extraRecords' => [
|
51
|
-
{
|
52
|
-
'name' => 'Name 1',
|
53
|
-
'extraid' => 1
|
54
|
-
}, [
|
55
|
-
'',
|
56
|
-
{
|
57
|
-
'name' => 'Name 2',
|
58
|
-
'extraid' => 2
|
59
|
-
}
|
60
|
-
]
|
61
|
-
]
|
62
|
-
}
|
63
|
-
role = DummyRole.new(1)
|
64
|
-
section = Osm::Section.from_api(1, 'Name', data, role)
|
28
|
+
it "Create" do
|
29
|
+
section = Osm::Section.new(@attributes)
|
65
30
|
|
66
31
|
section.id.should == 1
|
67
32
|
section.name.should == 'Name'
|
68
|
-
section.subscription_level.should == :
|
33
|
+
section.subscription_level.should == :silver
|
69
34
|
section.subscription_expires.should == Date.today + 60
|
70
35
|
section.type.should == :cubs
|
71
36
|
section.num_scouts.should == 10
|
72
|
-
section.column_names.should == {}
|
73
|
-
section.fields.should == {}
|
74
|
-
section.intouch_fields.should == {}
|
75
|
-
section.mobile_fields.should == {}
|
76
|
-
section.
|
77
|
-
section.
|
78
|
-
section.flexi_records
|
79
|
-
section.flexi_records[1].name.should == 'Name 2'
|
80
|
-
section.role.should == role
|
81
|
-
|
37
|
+
section.column_names.should == {:column_names => 'names'}
|
38
|
+
section.fields.should == {:fields => true}
|
39
|
+
section.intouch_fields.should == {:intouch_fields => true}
|
40
|
+
section.mobile_fields.should == {:mobile_fields => true}
|
41
|
+
section.group_id.should == 3
|
42
|
+
section.group_name.should == '3rd Somewhere'
|
43
|
+
section.flexi_records.should == []
|
82
44
|
section.valid?.should be_true
|
83
45
|
end
|
84
46
|
|
47
|
+
|
85
48
|
it "Create has sensible defaults" do
|
86
49
|
section = Osm::Section.new
|
87
50
|
|
@@ -97,67 +60,157 @@ describe "Section" do
|
|
97
60
|
end
|
98
61
|
|
99
62
|
|
100
|
-
|
101
|
-
|
102
|
-
|
63
|
+
describe "Using the API" do
|
64
|
+
|
65
|
+
before :each do
|
66
|
+
body = [
|
67
|
+
{"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}}", "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}},
|
68
|
+
{"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}}
|
69
|
+
]
|
70
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body.to_json)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "Gets all sections" do
|
74
|
+
sections = Osm::Section.get_all(@api)
|
75
|
+
sections.map{ |i| i.id }.should == [1, 2]
|
76
|
+
|
77
|
+
section = sections[0]
|
78
|
+
section.id.should == 1
|
79
|
+
section.name.should == 'Section 1'
|
80
|
+
section.subscription_level.should == :bronze
|
81
|
+
section.subscription_expires.should == Date.new(2013, 1, 5)
|
82
|
+
section.type.should == :beavers
|
83
|
+
section.num_scouts.should == 10
|
84
|
+
section.column_names.should == {:column_names => 'names'}
|
85
|
+
section.fields.should == {:fields => true}
|
86
|
+
section.intouch_fields.should == {:intouch_fields => true}
|
87
|
+
section.mobile_fields.should == {:mobile_fields => true}
|
88
|
+
section.group_id.should == 3
|
89
|
+
section.group_name.should == '3rd Somewhere'
|
90
|
+
section.flexi_records.size.should == 1
|
91
|
+
section.flexi_records[0].id.should == 111
|
92
|
+
section.flexi_records[0].name.should == 'Flexi Record 1'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "Gets a section" do
|
96
|
+
section = Osm::Section.get(@api, 1)
|
97
|
+
section.should_not be_nil
|
98
|
+
section.id.should == 1
|
99
|
+
end
|
100
|
+
|
101
|
+
it "Fetches user's permissions" do
|
102
|
+
permissions = Osm::Section.fetch_user_permissions(@api)
|
103
|
+
permissions[1].should_not be_nil
|
104
|
+
permissions[1].should == {
|
105
|
+
:badge => [:read],
|
106
|
+
:member => [:read, :write],
|
107
|
+
:user => [:read, :write, :administer],
|
108
|
+
:register => [:read, :write, :administer],
|
109
|
+
:contact => [:read, :write, :administer],
|
110
|
+
:programme => [:read, :write, :administer],
|
111
|
+
:originator => [],
|
112
|
+
:events => [:read, :write, :administer],
|
113
|
+
:finance => [:read, :write, :administer],
|
114
|
+
:flexi => [:read, :write, :administer],
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
it "Gets the section's notepad" do
|
119
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getNotepads", :body => {"1" => "Section 1", "2" => "Section 2"}.to_json)
|
120
|
+
section = Osm::Section.get(@api, 1)
|
121
|
+
section.should_not be_nil
|
122
|
+
section.get_notepad(@api).should == 'Section 1'
|
123
|
+
end
|
103
124
|
|
104
|
-
section1.should == section2
|
105
125
|
end
|
106
126
|
|
107
|
-
it "Compares two non-matching sections" do
|
108
|
-
section1 = Osm::Section.new(@attributes)
|
109
|
-
section2 = Osm::Section.new(@attributes.merge(:id => 2))
|
110
127
|
|
111
|
-
|
128
|
+
describe "Compare two sections" do
|
129
|
+
|
130
|
+
it "They match" do
|
131
|
+
section1 = Osm::Section.new(@attributes)
|
132
|
+
section2 = Osm::Section.new(@attributes)
|
133
|
+
|
134
|
+
section1.should == section2
|
135
|
+
end
|
136
|
+
|
137
|
+
it "They don't match" do
|
138
|
+
section1 = Osm::Section.new(@attributes)
|
139
|
+
section2 = Osm::Section.new(@attributes.merge(:id => 2))
|
140
|
+
|
141
|
+
section1.should_not == section2
|
142
|
+
end
|
143
|
+
|
112
144
|
end
|
113
145
|
|
114
146
|
|
115
|
-
it "Sorts by
|
116
|
-
section1 = Osm::Section.new(@attributes.merge(:
|
117
|
-
section2 = Osm::Section.new(@attributes.merge(:
|
147
|
+
it "Sorts by Group Name then section type (age order)" do
|
148
|
+
section1 = Osm::Section.new(@attributes.merge(:group_id => 1, :group_name => '1st Somewhere', :type => :beavers))
|
149
|
+
section2 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :beavers))
|
150
|
+
section3 = Osm::Section.new(@attributes.merge(:group_id => 2, :group_name => '2nd Somewhere', :type => :cubs))
|
118
151
|
|
119
|
-
[section2, section1].sort.should == [section1, section2]
|
152
|
+
[section2, section3, section1].sort.should == [section1, section2, section3]
|
120
153
|
end
|
121
154
|
|
122
155
|
|
123
|
-
|
124
|
-
unknown
|
125
|
-
beavers
|
126
|
-
cubs
|
127
|
-
scouts
|
128
|
-
explorers = Osm::Section.new(
|
129
|
-
adults
|
130
|
-
waiting
|
156
|
+
describe "Correctly works out the section type" do
|
157
|
+
unknown = Osm::Section.new(:type => :abc)
|
158
|
+
beavers = Osm::Section.new(:type => :beavers)
|
159
|
+
cubs = Osm::Section.new(:type => :cubs)
|
160
|
+
scouts = Osm::Section.new(:type => :scouts)
|
161
|
+
explorers = Osm::Section.new(:type => :explorers)
|
162
|
+
adults = Osm::Section.new(:type => :adults)
|
163
|
+
waiting = Osm::Section.new(:type => :waiting)
|
131
164
|
|
132
|
-
{:beavers => beavers, :cubs => cubs, :scouts => scouts, :explorers => explorers, :adults => adults, :waiting => waiting, :
|
133
|
-
|
134
|
-
|
165
|
+
{:beavers => beavers, :cubs => cubs, :scouts => scouts, :explorers => explorers, :adults => adults, :waiting => waiting, :unknown => unknown}.each do |section_type, section|
|
166
|
+
it "For a #{section_type} section" do
|
167
|
+
[:beavers, :cubs, :scouts, :explorers, :adults, :waiting].each do |type|
|
168
|
+
section.send("#{type.to_s}?").should == (section_type == type)
|
169
|
+
end
|
135
170
|
end
|
136
171
|
end
|
137
172
|
end
|
138
173
|
|
139
174
|
|
140
|
-
|
141
|
-
unknown = Osm::Section.new(
|
142
|
-
beavers = Osm::Section.new(
|
143
|
-
cubs = Osm::Section.new(
|
144
|
-
scouts = Osm::Section.new(
|
145
|
-
explorers = Osm::Section.new(
|
146
|
-
adults = Osm::Section.new(
|
147
|
-
waiting = Osm::Section.new(
|
175
|
+
describe "Correctly works out if the section is a youth section" do
|
176
|
+
unknown = Osm::Section.new(:type => :abc)
|
177
|
+
beavers = Osm::Section.new(:type => :beavers)
|
178
|
+
cubs = Osm::Section.new(:type => :cubs)
|
179
|
+
scouts = Osm::Section.new(:type => :scouts)
|
180
|
+
explorers = Osm::Section.new(:type => :explorers)
|
181
|
+
adults = Osm::Section.new(:type => :adults)
|
182
|
+
waiting = Osm::Section.new(:type => :waiting)
|
148
183
|
|
149
184
|
[beavers, cubs, scouts, explorers].each do |section|
|
150
|
-
section.
|
185
|
+
it "For a #{section.type} section" do
|
186
|
+
section.youth_section?.should be_true
|
187
|
+
end
|
151
188
|
end
|
152
189
|
[adults, waiting, unknown].each do |section|
|
153
|
-
section.
|
190
|
+
it "For a #{section.type} section" do
|
191
|
+
section.youth_section?.should be_false
|
192
|
+
end
|
154
193
|
end
|
155
194
|
end
|
156
195
|
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
describe "Section::FlexiRecord" do
|
201
|
+
|
202
|
+
it "Create" do
|
203
|
+
fr = Osm::Section::FlexiRecord.new(:id => 1, :name => 'Name')
|
204
|
+
|
205
|
+
fr.id.should == 1
|
206
|
+
fr.name.should == 'Name'
|
207
|
+
fr.valid?.should be_true
|
208
|
+
end
|
209
|
+
|
157
210
|
|
158
211
|
it "Sorts Flexi Records by name" do
|
159
|
-
fr1 = Osm::Section::FlexiRecord.new(:id =>
|
160
|
-
fr2 = Osm::Section::FlexiRecord.new(:id =>
|
212
|
+
fr1 = Osm::Section::FlexiRecord.new(:id => 3, :name => 'A')
|
213
|
+
fr2 = Osm::Section::FlexiRecord.new(:id => 2, :name => 'B')
|
161
214
|
fr3 = Osm::Section::FlexiRecord.new(:id => 1, :name => 'C')
|
162
215
|
records = [fr2, fr1, fr3]
|
163
216
|
|
@@ -165,3 +218,66 @@ describe "Section" do
|
|
165
218
|
end
|
166
219
|
|
167
220
|
end
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
describe "Online Scout Manager API Strangeness" do
|
225
|
+
|
226
|
+
it "handles a section with no type" do
|
227
|
+
body = '[{"sectionConfig":"{\"subscription_level\":3,\"subscription_expires\":\"2013-01-05\",\"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\":[{\"name\":\"Subs\",\"extraid\":\"529\"}],\"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":"1","sectionname":"Section 1","section":"cubs","isDefault":"1","permissions":{"badge":100,"member":100,"user":100,"register":100,"contact":100,"programme":100,"originator":1,"events":100,"finance":100,"flexi":100}}]'
|
228
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
|
229
|
+
|
230
|
+
sections = Osm::Section.get_all(@api)
|
231
|
+
sections.size.should == 1
|
232
|
+
section = sections[0]
|
233
|
+
section.should_not be_nil
|
234
|
+
section.type.should == :unknown
|
235
|
+
end
|
236
|
+
|
237
|
+
it "handles strange extra records when getting roles" do
|
238
|
+
body = '[{"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\":[[\"1\",{\"name\":\"Subs\",\"extraid\":\"529\"}],[\"2\",{\"name\":\"Subs 2\",\"extraid\":\"530\"}]],\"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":"1","sectionname":"Section 1","section":"cubs","isDefault":"1","permissions":{"badge":100,"member":100,"user":100,"register":100,"contact":100,"programme":100,"originator":1,"events":100,"finance":100,"flexi":100}}]'
|
239
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
|
240
|
+
|
241
|
+
sections = Osm::Section.get_all(@api)
|
242
|
+
sections.size.should == 1
|
243
|
+
sections[0].should_not be_nil
|
244
|
+
end
|
245
|
+
|
246
|
+
it "handles a section config where fields is an empty array" do
|
247
|
+
body = '[{"sectionConfig":"{\"subscription_level\":3,\"subscription_expires\":\"2013-01-05\",\"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\":[{\"name\":\"Subs\",\"extraid\":\"529\"}],\"wizard\":\"false\",\"fields\":[],\"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":"1","sectionname":"Section 1","section":"cubs","isDefault":"1","permissions":{"badge":100,"member":100,"user":100,"register":100,"contact":100,"programme":100,"originator":1,"events":100,"finance":100,"flexi":100}}]'
|
248
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
|
249
|
+
|
250
|
+
sections = Osm::Section.get_all(@api)
|
251
|
+
sections.size.should == 1
|
252
|
+
section = sections[0]
|
253
|
+
section.should_not be_nil
|
254
|
+
section.fields.should == {}
|
255
|
+
end
|
256
|
+
|
257
|
+
it "handles a section's flexi records being a hash" do
|
258
|
+
body = [
|
259
|
+
{"sectionConfig"=>"{\"subscription_level\":1,\"subscription_expires\":\"2013-01-05\",\"sectionType\":\"beavers\",\"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\":{\"1\":{\"name\":\"Flexi Record 1\",\"extraid\":\"1\"},\"2\":{\"name\":\"Flexi Record 2\",\"extraid\":\"2\"}},\"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"=>"3rd Somewhere", "groupid"=>"3", "groupNormalised"=>"1", "sectionid"=>"1", "sectionname"=>"Section 1", "section"=>"beavers", "isDefault"=>"1", "permissions"=>{"badge"=>100, "member"=>100, "user"=>100, "register"=>100, "contact"=>100, "programme"=>100, "originator"=>1, "events"=>100, "finance"=>100, "flexi"=>100}},
|
260
|
+
]
|
261
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body.to_json)
|
262
|
+
|
263
|
+
sections = Osm::Section.get_all(@api)
|
264
|
+
sections.size.should == 1
|
265
|
+
section = sections[0]
|
266
|
+
section.should_not be_nil
|
267
|
+
section.flexi_records.size.should == 2
|
268
|
+
fr = section.flexi_records[0]
|
269
|
+
fr.id.should == 1
|
270
|
+
fr.name.should == 'Flexi Record 1'
|
271
|
+
end
|
272
|
+
|
273
|
+
it "handles an empty array representing no notepads" do
|
274
|
+
body = [{"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}}", "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}}]
|
275
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body.to_json)
|
276
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getNotepads", :body => '[]')
|
277
|
+
|
278
|
+
section = Osm::Section.get(@api, 1)
|
279
|
+
section.should_not be_nil
|
280
|
+
section.get_notepad(@api).should == ''
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|