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,48 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+
5
+ describe "Online Scout Manager API Strangeness" do
6
+
7
+ before(:each) do
8
+ Osm::Api.configure({:api_id=>'1234', :api_token=>'12345678', :api_name=>'API', :api_site=>:scout})
9
+ @api = Osm::Api.new('2345', 'abcd')
10
+ end
11
+
12
+ it "handles a section with no type" do
13
+ 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}}]'
14
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
15
+
16
+ @api.get_section(1).type.should == :unknown
17
+ end
18
+
19
+
20
+ it "handles strange extra records when getting roles" do
21
+ 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}}]'
22
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
23
+
24
+ @api.get_roles()[0].should_not == nil
25
+ end
26
+
27
+
28
+ it "handles an empty array representing no due badges" do
29
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=outstandingBadges&section=cubs&sectionid=1&termid=1", :body => '[]')
30
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :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\":[{\"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 Name","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}}]')
31
+ @api.get_due_badges(1, 1).should_not == nil
32
+ end
33
+
34
+
35
+ it "handles an empty array representing no notepads" do
36
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getNotepads", :body => '[]')
37
+ @api.get_notepad(1).should == nil
38
+ end
39
+
40
+
41
+ it "handles a non existant array when no events" do
42
+ data = '{"identifier":"eventid","label":"name"}'
43
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents&sectionid=1", :body => data)
44
+
45
+ @api.get_events(1).should == []
46
+ end
47
+
48
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "DueBadge" do
5
+
6
+ it "Create" do
7
+ data = {
8
+ 'pending' => {
9
+ 'badge_name' => [
10
+ {
11
+ 'scoutid' => '1',
12
+ 'firstname' => 'John',
13
+ 'lastname' => 'Doe',
14
+ 'completed' => '',
15
+ 'extra' => '',
16
+ }
17
+ ],
18
+ 'cubs_core_participation' => [{
19
+ 'sid' => '2',
20
+ 'firstname' => 'Jane',
21
+ 'lastname' => 'Doe',
22
+ 'completed' => '3',
23
+ 'extra' => 'Lvl 3'
24
+ }, {
25
+ 'sid' => '1',
26
+ 'firstname' => 'John',
27
+ 'lastname' => 'Doe',
28
+ 'completed' => '2',
29
+ 'extra' => 'Lvl 2'
30
+ }
31
+ ]
32
+ },
33
+
34
+ 'description' => {
35
+ 'badge_name' => {
36
+ 'name' => 'Badge Name',
37
+ 'section' => 'cubs',
38
+ 'type' => 'activity',
39
+ 'badge' => 'badge_name'
40
+ },
41
+ 'cubs_core_participation' => {
42
+ 'name' => 'Participation',
43
+ 'section' => 'cubs',
44
+ 'type' => 'core',
45
+ 'badge' => 'participation'
46
+ }
47
+ }
48
+ }
49
+ db = Osm::DueBadges.new(data)
50
+
51
+ db.empty?.should == false
52
+ db.descriptions.should == {:badge_name=>{:name=>"Badge Name", :section=>:cubs, :type=>:activity, :badge=>"badge_name"}, :cubs_core_participation=>{:name=>"Participation", :section=>:cubs, :type=>:core, :badge=>"participation"}}
53
+ db.by_member.should == {"John Doe"=>[{:badge=>:badge_name, :extra_information=>""}, {:badge=>:cubs_core_participation, :extra_information=>"Lvl 2"}], "Jane Doe"=>[{:badge=>:cubs_core_participation, :extra_information=>"Lvl 3"}]}
54
+ db.totals.should == {:badge_name=>{""=>1}, :cubs_core_participation=>{"Lvl 3"=>1, "Lvl 2"=>1}}
55
+ end
56
+
57
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
4
+
5
+ describe "Event" do
6
+
7
+ it "Create" do
8
+ data = {
9
+ 'eventid' => 1,
10
+ 'sectionid' => 2,
11
+ 'name' => 'Event name',
12
+ 'startdate' => '2001-01-02',
13
+ 'starttime' => '12:00:00',
14
+ 'enddate' => '2001-01-02',
15
+ 'endtime' => '13:00:00',
16
+ 'cost' => 'Free',
17
+ 'location' => 'Somewhere',
18
+ 'notes' => 'None'
19
+ }
20
+ event = Osm::Event.new(data)
21
+
22
+ event.id.should == 1
23
+ event.section_id.should == 2
24
+ event.name.should == 'Event name'
25
+ event.start.should == DateTime.new(2001, 1, 2, 12, 0, 0)
26
+ event.end.should == DateTime.new(2001, 1, 2, 13, 0, 0)
27
+ event.cost.should == 'Free'
28
+ event.location.should == 'Somewhere'
29
+ event.notes.should == 'None'
30
+ end
31
+
32
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Grouping" do
5
+
6
+ it "Create" do
7
+ data = {
8
+ 'patrolid' => 1,
9
+ 'name' => 'Patrol Name',
10
+ 'active' => 1
11
+ }
12
+ patrol = Osm::Grouping.new(data)
13
+
14
+ patrol.id.should == 1
15
+ patrol.name.should == 'Patrol Name'
16
+ patrol.active.should == true
17
+ end
18
+
19
+ end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Member" do
5
+
6
+ it "Create" do
7
+ data = {
8
+ 'scoutid' => 1,
9
+ 'sectionid' => 2,
10
+ 'type' => '',
11
+ 'firstname' => 'First',
12
+ 'lastname' => 'Last',
13
+ 'email1' => 'email1@example.com',
14
+ 'email2' => 'email2@example.com',
15
+ 'email3' => 'email3@example.com',
16
+ 'email4' => 'email4@example.com',
17
+ 'phone1' => '11111 111111',
18
+ 'phone2' => '222222',
19
+ 'phone3' => '+33 3333 333333',
20
+ 'phone4' => '4444 444 444',
21
+ 'address' => '1 Some Road',
22
+ 'address2' => '',
23
+ 'dob' => '2000-01-02',
24
+ 'started' => '2006-01-02',
25
+ 'joining_in_yrs' => '2',
26
+ 'parents' => 'John and Jane Doe',
27
+ 'notes' => 'None',
28
+ 'medical' => 'Nothing',
29
+ 'religion' => 'Unknown',
30
+ 'school'=> 'Some School',
31
+ 'ethnicity' => 'Yes',
32
+ 'subs' => 'Upto end of 2007',
33
+ 'patrolid' => '3',
34
+ 'patrolleader' => 0,
35
+ 'joined' => '2006-01-07',
36
+ 'age' => '06/07',
37
+ 'yrs' => 1,
38
+ 'patrol' => 'Blue',
39
+ }
40
+ member = Osm::Member.new(data)
41
+
42
+ member.id.should == 1
43
+ member.section_id.should == 2
44
+ member.type.should == ''
45
+ member.first_name.should == 'First'
46
+ member.last_name.should == 'Last'
47
+ member.email1.should == 'email1@example.com'
48
+ member.email2.should == 'email2@example.com'
49
+ member.email3.should == 'email3@example.com'
50
+ member.email4.should == 'email4@example.com'
51
+ member.phone1.should == '11111 111111'
52
+ member.phone2.should == '222222'
53
+ member.phone3.should == '+33 3333 333333'
54
+ member.phone4.should == '4444 444 444'
55
+ member.address.should == '1 Some Road'
56
+ member.address2.should == ''
57
+ member.date_of_birth.should == Date.new(2000, 1, 2)
58
+ member.started.should == Date.new(2006, 1, 2)
59
+ member.joined_in_years.should == 2
60
+ member.parents.should == 'John and Jane Doe'
61
+ member.notes.should == 'None'
62
+ member.medical.should == 'Nothing'
63
+ member.religion.should == 'Unknown'
64
+ member.school.should == 'Some School'
65
+ member.ethnicity.should == 'Yes'
66
+ member.subs.should == 'Upto end of 2007'
67
+ member.grouping_id.should == 3
68
+ member.grouping_leader.should == 0
69
+ member.joined.should == Date.new(2006, 1, 7)
70
+ member.age.should == '06/07'
71
+ member.joined_years.should == 1
72
+ member.patrol.should == 'Blue'
73
+ end
74
+
75
+
76
+ it "Provides member's full name" do
77
+ data = {
78
+ 'firstname' => 'First',
79
+ 'lastname' => 'Last',
80
+ }
81
+ member = Osm::Member.new(data)
82
+
83
+ member.name.should == 'First Last'
84
+ member.name('_').should == 'First_Last'
85
+ end
86
+
87
+
88
+ it "Provides each part of age" do
89
+ data = {
90
+ 'age' => '06/07',
91
+ }
92
+ member = Osm::Member.new(data)
93
+
94
+ member.age_years.should == 6
95
+ member.age_months.should == 7
96
+ end
97
+
98
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
4
+
5
+ describe "Online Scout Manager" do
6
+
7
+ describe "Make array of symbols" do
8
+ it "turns array of strings to an array of symbols" do
9
+ start = %w{first second third}
10
+ Osm::make_array_of_symbols(start).should == [:first, :second, :third]
11
+ end
12
+ end
13
+
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
+ describe "Make a DateTime" do
46
+ it "is given a date and a time" do
47
+ Osm::make_datetime('2001-02-03', '04:05:06').should == DateTime.new(2001, 02, 03, 04, 05, 06)
48
+ end
49
+
50
+ it "is given just a date" do
51
+ Osm::make_datetime('2001-02-03', '').should == DateTime.new(2001, 02, 03, 00, 00, 00)
52
+ end
53
+
54
+ it "is given neither" do
55
+ Osm::make_datetime('', '').should == nil
56
+ end
57
+
58
+ it "is given an invalid date" do
59
+ Osm::make_datetime('No date here1', '04:05:06').should == nil
60
+ end
61
+
62
+ it "is given an invalid time" do
63
+ Osm::make_datetime('2001-02-03', 'No time here!').should == nil
64
+ end
65
+
66
+ it "is given just an invalid date" do
67
+ Osm::make_datetime('No date here1', nil).should == nil
68
+ end
69
+ end
70
+
71
+
72
+ describe "Parse a date" do
73
+ it "is given a valid date string" do
74
+ Osm::parse_date('2001-02-03').should == Date.new(2001, 02, 03)
75
+ end
76
+
77
+ it "is given an invalid date string" do
78
+ Osm::parse_date('No date here!').should == nil
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Programme Activity" do
5
+
6
+ it "Create" do
7
+ data = {
8
+ 'eveningid' => 1,
9
+ 'activityid' => 2,
10
+ 'title' => 'Activity Name',
11
+ 'notes' => 'Notes',
12
+ }
13
+ pa = Osm::ProgrammeActivity.new(data)
14
+
15
+ pa.evening_id.should == 1
16
+ pa.activity_id.should == 2
17
+ pa.title.should == 'Activity Name'
18
+ pa.notes.should == 'Notes'
19
+ end
20
+
21
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
4
+
5
+ describe "Programme Item" do
6
+
7
+ it "Create" do
8
+ data = {
9
+ 'eveningid' => 1,
10
+ 'sectionid' => 2,
11
+ 'title' => 'Evening Name',
12
+ 'notesforparents' => 'Notes for parents',
13
+ 'games' => 'Games',
14
+ 'prenotes' => 'Before',
15
+ 'postnotes' => 'After',
16
+ 'leaders' => 'Leaders',
17
+ 'starttime' => '19:00',
18
+ 'endtime' => '21:00',
19
+ 'meetingdate' => '2000-01-02',
20
+ }
21
+ pi = Osm::ProgrammeItem.new(data, [])
22
+
23
+ pi.evening_id.should == 1
24
+ pi.section_id.should == 2
25
+ pi.title.should == 'Evening Name'
26
+ pi.notes_for_parents.should == 'Notes for parents'
27
+ pi.games.should == 'Games'
28
+ pi.pre_notes.should == 'Before'
29
+ pi.post_notes.should == 'After'
30
+ pi.leaders.should == 'Leaders'
31
+ pi.start_time.should == '19:00'
32
+ pi.end_time.should == '21:00'
33
+ pi.meeting_date.should == Date.new(2000, 1, 2)
34
+ end
35
+
36
+
37
+ it "Raises exceptions when trying to set invalid times" do
38
+ pi = Osm::ProgrammeItem.new({}, [])
39
+
40
+ expect{ pi.start_time = 'abcde' }.to raise_error(ArgumentError)
41
+ expect{ pi.start_time = '24:00' }.to raise_error(ArgumentError)
42
+ expect{ pi.start_time = '10:61' }.to raise_error(ArgumentError)
43
+ pi.start_time = '12:34'
44
+ pi.start_time.should == '12:34'
45
+
46
+ expect{ pi.end_time = 'abcde' }.to raise_error(ArgumentError)
47
+ expect{ pi.end_time = '24:00' }.to raise_error(ArgumentError)
48
+ expect{ pi.end_time = '10:61' }.to raise_error(ArgumentError)
49
+ pi.end_time = '23:45'
50
+ pi.end_time.should == '23:45'
51
+ end
52
+
53
+
54
+ it "Makes a list of activities to save for OSM's API" do
55
+ pi = Osm::ProgrammeItem.new({}, [{
56
+ 'eveningid' => 1,
57
+ 'activityid' => 2,
58
+ 'title' => 'Activity Name',
59
+ 'notes' => 'Notes',
60
+ }])
61
+ pi.activities_for_saving.should == '[{"activityid":2,"notes":"Notes"}]'
62
+ end
63
+
64
+ end
@@ -0,0 +1,111 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
4
+
5
+
6
+ describe "Role" do
7
+
8
+ it "Create" do
9
+ data = {
10
+ 'sectionid' => 1,
11
+ 'sectionname' => 'A Section',
12
+ 'sectionConfig' => '{}',
13
+ 'groupname' => 'A Group',
14
+ 'groupid' => '2',
15
+ 'groupNormalised' => '3',
16
+ 'isDefault' => '1',
17
+ 'permissions' => {}
18
+ }
19
+ role = Osm::Role.new(data)
20
+
21
+ role.section.id.should == 1
22
+ role.section.name.should == 'A Section'
23
+ role.group_id.should == 2
24
+ role.group_name.should == 'A Group'
25
+ end
26
+
27
+
28
+ it "Compares two matching roles" do
29
+ role1 = Osm::Role.new({'sectionConfig' => '{}'})
30
+ role2 = Osm::Role.new({'sectionConfig' => '{}'})
31
+ role1.should == role2
32
+ end
33
+
34
+ it "Compares two non-matching roles" do
35
+ role1 = Osm::Role.new({'sectionid' => 1, 'sectionConfig' => '{}'})
36
+ role2 = Osm::Role.new({'sectionid' => 2, 'sectionConfig' => '{}'})
37
+
38
+ role1.should_not == role2
39
+ end
40
+
41
+
42
+ it "Sorts by Group Name then section type (age order)" do
43
+ role1 = Osm::Role.new({'groupname' => 'Group A', 'sectionConfig' => '{}'})
44
+ role2 = Osm::Role.new({'groupname' => 'Group B', 'sectionConfig' => '{"sectionType":"beavers"}'})
45
+ role3 = Osm::Role.new({'groupname' => 'Group B', 'sectionConfig' => '{"sectionType":"cubs"}'})
46
+ role4 = Osm::Role.new({'groupname' => 'Group B', 'sectionConfig' => '{"sectionType":"scouts"}'})
47
+ role5 = Osm::Role.new({'groupname' => 'Group B', 'sectionConfig' => '{"sectionType":"explorers"}'})
48
+ role6 = Osm::Role.new({'groupname' => 'Group B', 'sectionConfig' => '{"sectionType":"waiting"}'})
49
+ role7 = Osm::Role.new({'groupname' => 'Group B', 'sectionConfig' => '{"sectionType":"adults"}'})
50
+ role8 = Osm::Role.new({'groupname' => 'Group C', 'sectionConfig' => '{}'})
51
+
52
+ data = [role8, role5, role3, role7, role2, role4, role1, role6]
53
+ data.sort.should == [role1, role2, role3, role4, role5, role6, role7, role8]
54
+ end
55
+
56
+
57
+ it "Provides a long name for the role" do
58
+ role = Osm::Role.new({
59
+ 'sectionname' => 'A Section',
60
+ 'sectionConfig' => '{}',
61
+ 'groupname' => 'A Group',
62
+ })
63
+ role.long_name.should == 'A Section (A Group)'
64
+
65
+ role = Osm::Role.new({
66
+ 'sectionname' => 'A Section',
67
+ 'sectionConfig' => '{}',
68
+ })
69
+ role.long_name.should == 'A Section'
70
+ end
71
+
72
+
73
+ it "Provides a full name for the role" do
74
+ role = Osm::Role.new({
75
+ 'sectionname' => 'A Section',
76
+ 'sectionConfig' => '{}',
77
+ 'groupname' => 'A Group',
78
+ })
79
+ role.full_name.should == 'A Group A Section'
80
+
81
+ role = Osm::Role.new({
82
+ 'sectionname' => 'A Section',
83
+ 'sectionConfig' => '{}',
84
+ })
85
+ role.full_name.should == 'A Section'
86
+ end
87
+
88
+
89
+ it "Allows interegation of the permissions hash" do
90
+ role = Osm::Role.new({
91
+ 'sectionConfig' => '{}',
92
+ 'permissions' => {
93
+ 'read_only' => 10,
94
+ 'read_write' => 20,
95
+ 'administer' => 100
96
+ }
97
+ })
98
+
99
+ role.can_read?(:read_only).should == true
100
+ role.can_read?(:read_write).should == true
101
+ role.can_read?(:administer).should == true
102
+
103
+ role.can_write?(:read_only).should == false
104
+ role.can_write?(:read_write).should == true
105
+ role.can_write?(:administer).should == true
106
+
107
+ role.can_read?(:non_existant).should == false
108
+ role.can_write?(:non_existant).should == false
109
+ end
110
+
111
+ end