osm 0.0.26 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/due_badges_spec.rb
CHANGED
@@ -46,8 +46,9 @@ describe "DueBadge" do
|
|
46
46
|
}
|
47
47
|
}
|
48
48
|
}
|
49
|
-
|
49
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=outstandingBadges§ion=cubs§ionid=1&termid=2", :body => data.to_json)
|
50
50
|
|
51
|
+
db = Osm::DueBadges.get(@api, Osm::Section.new(:id => 1, :type => :cubs), 2)
|
51
52
|
db.empty?.should == false
|
52
53
|
db.descriptions.should == {'badge_name_1'=>'Badge Name', 'staged_staged_participation_2'=>'Participation (Level 2)'}
|
53
54
|
db.by_member.should == {'John Doe'=>['badge_name_1', 'staged_staged_participation_2'], 'Jane Doe'=>['staged_staged_participation_2']}
|
@@ -55,4 +56,10 @@ describe "DueBadge" do
|
|
55
56
|
db.valid?.should be_true
|
56
57
|
end
|
57
58
|
|
59
|
+
it "handles an empty array representing no due badges" do
|
60
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=outstandingBadges§ion=cubs§ionid=1&termid=2", :body => '[]')
|
61
|
+
db = Osm::DueBadges.get(@api, Osm::Section.new(:id => 1, :type => :cubs), 2)
|
62
|
+
db.should_not == nil
|
63
|
+
end
|
64
|
+
|
58
65
|
end
|
data/spec/osm/evening_spec.rb
CHANGED
@@ -4,8 +4,8 @@ require 'date'
|
|
4
4
|
|
5
5
|
describe "Evening" do
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
it "Create" do
|
8
|
+
e = Osm::Evening.new(
|
9
9
|
:id => 1,
|
10
10
|
:section_id => 2,
|
11
11
|
:title => 'Evening Name',
|
@@ -17,30 +17,8 @@ describe "Evening" do
|
|
17
17
|
:start_time => '19:00',
|
18
18
|
:finish_time => '21:00',
|
19
19
|
:meeting_date => Date.new(2000, 01, 02),
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
it "Create from API data" do
|
24
|
-
data = {
|
25
|
-
'eveningid' => 1,
|
26
|
-
'sectionid' => 2,
|
27
|
-
'title' => 'Evening Name',
|
28
|
-
'notesforparents' => 'Notes for parents',
|
29
|
-
'games' => 'Games',
|
30
|
-
'prenotes' => 'Before',
|
31
|
-
'postnotes' => 'After',
|
32
|
-
'leaders' => 'Leaders',
|
33
|
-
'starttime' => '19:00',
|
34
|
-
'endtime' => '21:00',
|
35
|
-
'meetingdate' => '2000-01-02',
|
36
|
-
}
|
37
|
-
activities = [{
|
38
|
-
'eveningid' => 1,
|
39
|
-
'activityid' => 2,
|
40
|
-
'title' => 'Activity Name',
|
41
|
-
'notes' => 'Notes',
|
42
|
-
}]
|
43
|
-
e = Osm::Evening.from_api(data, activities)
|
20
|
+
:activities => []
|
21
|
+
)
|
44
22
|
|
45
23
|
e.id.should == 1
|
46
24
|
e.section_id.should == 2
|
@@ -53,41 +31,128 @@ describe "Evening" do
|
|
53
31
|
e.start_time.should == '19:00'
|
54
32
|
e.finish_time.should == '21:00'
|
55
33
|
e.meeting_date.should == Date.new(2000, 1, 2)
|
34
|
+
e.activities.should == []
|
35
|
+
e.valid?.should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "Create Evening::Activity" do
|
39
|
+
ea = Osm::Evening::Activity.new(
|
40
|
+
:activity_id => 2,
|
41
|
+
:title => 'Activity Name',
|
42
|
+
:notes => 'Notes',
|
43
|
+
)
|
56
44
|
|
57
|
-
ea = e.activities[0]
|
58
45
|
ea.activity_id.should == 2
|
59
46
|
ea.title.should == 'Activity Name'
|
60
47
|
ea.notes.should == 'Notes'
|
61
|
-
|
62
|
-
e.valid?.should be_true
|
48
|
+
ea.valid?.should be_true
|
63
49
|
end
|
64
50
|
|
65
51
|
|
66
|
-
|
67
|
-
data = @attributes.merge(
|
68
|
-
:activities => [ Osm::Evening::Activity.new(
|
69
|
-
:activity_id => 4,
|
70
|
-
:title => 'Activity Name',
|
71
|
-
:notes => 'Notes',
|
72
|
-
) ]
|
73
|
-
)
|
52
|
+
describe 'Using the API' do
|
74
53
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
54
|
+
it "Fetch the term's programme for a section" do
|
55
|
+
items = [{"eveningid" => "5", "sectionid" =>"3", "title" => "Weekly Meeting 1", "notesforparents" => "", "games" => "", "prenotes" => "", "postnotes" => "", "leaders" => "", "meetingdate" => "2001-02-03", "starttime" => "19:15:00", "endtime" => "20:30:00", "googlecalendar" => ""}]
|
56
|
+
activities = {"5" => [
|
57
|
+
{"activityid" => "6", "title" => "Activity 6", "notes" => "", "eveningid" => "5"},
|
58
|
+
{"activityid" => "7", "title" => "Activity 7", "notes" => "", "eveningid" => "5"}
|
59
|
+
]}
|
60
|
+
body = {"items" => items, "activities" => activities}
|
61
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/programme.php?action=getProgramme§ionid=3&termid=4", :body => body.to_json)
|
62
|
+
|
63
|
+
programme = Osm::Evening.get_programme(@api, 3, 4)
|
64
|
+
programme.size.should == 1
|
65
|
+
programme[0].is_a?(Osm::Evening).should be_true
|
66
|
+
programme[0].activities.size.should == 2
|
67
|
+
end
|
68
|
+
|
69
|
+
it "Fetch badge requirements for an evening" do
|
70
|
+
badges_body = [{'a'=>'a'},{'a'=>'A'}]
|
71
|
+
FakeWeb.register_uri(:post, 'https://www.onlinescoutmanager.co.uk/users.php?action=getActivityRequirements&date=2000-01-02§ionid=3§ion=cubs', :body => badges_body.to_json)
|
72
|
+
roles_body = [
|
73
|
+
{"sectionConfig"=>"{\"subscription_level\":1,\"subscription_expires\":\"2013-01-05\",\"sectionType\":\"cubs\",\"columnNames\":{\"column_names\":\"names\"},\"numscouts\":10,\"hasUsedBadgeRecords\":true,\"hasProgramme\":true,\"extraRecords\":[],\"wizard\":\"false\",\"fields\":{\"fields\":true},\"intouch\":{\"intouch_fields\":true},\"mobFields\":{\"mobile_fields\":true}}", "groupname"=>"3rd Somewhere", "groupid"=>"3", "groupNormalised"=>"1", "sectionid"=>"3", "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}},
|
74
|
+
]
|
75
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => roles_body.to_json)
|
92
76
|
|
77
|
+
evening = Osm::Evening.new(:meeting_date => Date.new(2000, 1, 2), :section_id => 3)
|
78
|
+
evening.get_badge_requirements(@api).should == badges_body
|
79
|
+
end
|
80
|
+
|
81
|
+
it "Create an evening (succeded)" do
|
82
|
+
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
|
83
|
+
post_data = {
|
84
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
85
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
86
|
+
'userid' => 'user_id',
|
87
|
+
'secret' => 'secret',
|
88
|
+
'meetingdate' => '2000-01-02',
|
89
|
+
'sectionid' => 1,
|
90
|
+
'activityid' => -1,
|
91
|
+
}
|
92
|
+
|
93
|
+
Osm::Term.stub(:get_for_section) { [] }
|
94
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
|
95
|
+
Osm::Evening.create(@api, 1, Date.new(2000, 1, 2)).should be_true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "Create an evening (failed)" do
|
99
|
+
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
|
100
|
+
post_data = {
|
101
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
102
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
103
|
+
'userid' => 'user_id',
|
104
|
+
'secret' => 'secret',
|
105
|
+
'meetingdate' => '2000-01-02',
|
106
|
+
'sectionid' => 1,
|
107
|
+
'activityid' => -1,
|
108
|
+
}
|
109
|
+
|
110
|
+
Osm::Term.stub(:get_for_section) { [] }
|
111
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
|
112
|
+
Osm::Evening.create(@api, 1, Date.new(2000, 1, 2)).should be_false
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
it "Update an evening (succeded)" do
|
117
|
+
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=editEvening'
|
118
|
+
post_data = {
|
119
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
120
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
121
|
+
'userid' => 'user_id',
|
122
|
+
'secret' => 'secret',
|
123
|
+
'eveningid' => 1, 'sectionid' => 2, 'meetingdate' => '2000-01-02', 'starttime' => nil,
|
124
|
+
'endtime' => nil, 'title' => 'Unnamed meeting', 'notesforparents' =>'', 'prenotes' => '',
|
125
|
+
'postnotes' => '', 'games' => '', 'leaders' => '', 'activity' => '[]',
|
126
|
+
}
|
127
|
+
Osm::Term.stub(:get_for_section) { [] }
|
128
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":0}'}) }
|
129
|
+
|
130
|
+
evening = Osm::Evening.new(:id=>1, :section_id=>2, :meeting_date=>Date.new(2000, 01, 02))
|
131
|
+
evening.update(@api).should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "Update an evening (failed)" do
|
135
|
+
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=editEvening'
|
136
|
+
post_data = {
|
137
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
138
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
139
|
+
'userid' => 'user_id',
|
140
|
+
'secret' => 'secret',
|
141
|
+
'eveningid' => 1, 'sectionid' => 2, 'meetingdate' => '2000-01-02', 'starttime' => nil,
|
142
|
+
'endtime' => nil, 'title' => 'Unnamed meeting', 'notesforparents' =>'', 'prenotes' => '',
|
143
|
+
'postnotes' => '', 'games' => '', 'leaders' => '', 'activity' => '[]',
|
144
|
+
}
|
145
|
+
Osm::Term.stub(:get_for_section) { [] }
|
146
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"result":1}'}) }
|
147
|
+
|
148
|
+
evening = Osm::Evening.new(:id=>1, :section_id=>2, :meeting_date=>Date.new(2000, 01, 02))
|
149
|
+
evening.update(@api).should be_false
|
150
|
+
end
|
151
|
+
|
152
|
+
it "Update an evening (invalid evening)" do
|
153
|
+
evening = Osm::Evening.new
|
154
|
+
expect{ evening.update(@api) }.to raise_error(Osm::ObjectIsInvalid)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
93
158
|
end
|
data/spec/osm/event_spec.rb
CHANGED
@@ -4,21 +4,20 @@ require 'date'
|
|
4
4
|
|
5
5
|
describe "Event" do
|
6
6
|
|
7
|
-
it "Create
|
7
|
+
it "Create Event" do
|
8
8
|
data = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
'archived' => '0',
|
9
|
+
:id => 1,
|
10
|
+
:section_id => 2,
|
11
|
+
:name => 'Event name',
|
12
|
+
:start => DateTime.new(2001, 1, 2, 12 ,0 ,0),
|
13
|
+
:finish => nil,
|
14
|
+
:cost => 'Free',
|
15
|
+
:location => 'Somewhere',
|
16
|
+
:notes => 'None',
|
17
|
+
:archived => '0',
|
18
|
+
:fields => {},
|
20
19
|
}
|
21
|
-
event = Osm::Event.
|
20
|
+
event = Osm::Event.new(data)
|
22
21
|
|
23
22
|
event.id.should == 1
|
24
23
|
event.section_id.should == 2
|
@@ -29,7 +28,358 @@ describe "Event" do
|
|
29
28
|
event.location.should == 'Somewhere'
|
30
29
|
event.notes.should == 'None'
|
31
30
|
event.archived.should be_false
|
31
|
+
event.fields.should == {}
|
32
32
|
event.valid?.should be_true
|
33
33
|
end
|
34
34
|
|
35
|
+
it "Create Event::Attendance" do
|
36
|
+
data = {
|
37
|
+
:member_id => 1,
|
38
|
+
:grouping_id => 2,
|
39
|
+
:row => 3,
|
40
|
+
:fields => {},
|
41
|
+
:event => Osm::Event.new(:id => 1, :section_id => 1, :name => 'Name', :fields => {})
|
42
|
+
}
|
43
|
+
|
44
|
+
ea = Osm::Event::Attendance.new(data)
|
45
|
+
ea.member_id.should == 1
|
46
|
+
ea.grouping_id.should == 2
|
47
|
+
ea.fields.should == {}
|
48
|
+
ea.row.should == 3
|
49
|
+
ea.valid?.should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
describe "Using the API" do
|
54
|
+
|
55
|
+
before :each do
|
56
|
+
events_body = {
|
57
|
+
'identifier' => 'eventid',
|
58
|
+
'label' => 'name',
|
59
|
+
'items' => [{
|
60
|
+
'eventid' => '2',
|
61
|
+
'name' => 'An Event',
|
62
|
+
'startdate' => '2001-02-03',
|
63
|
+
'enddate' => '2001-02-05',
|
64
|
+
'starttime' => '00:00:00',
|
65
|
+
'endtime' => '12:00:00',
|
66
|
+
'cost' => '0.00',
|
67
|
+
'location' => 'Somewhere',
|
68
|
+
'notes' => 'Notes',
|
69
|
+
'sectionid' => 1,
|
70
|
+
'googlecalendar' => nil,
|
71
|
+
'archived' => '0'
|
72
|
+
}]
|
73
|
+
}
|
74
|
+
|
75
|
+
fields_body = {
|
76
|
+
'config' => '[{"id":"f_1","name":"Field 1"}]'
|
77
|
+
}
|
78
|
+
|
79
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1&showArchived=true", :body => events_body.to_json)
|
80
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvent§ionid=1&eventid=2", :body => fields_body.to_json)
|
81
|
+
|
82
|
+
Osm::Model.stub(:get_user_permissions) { {:events => [:read, :write]} }
|
83
|
+
end
|
84
|
+
|
85
|
+
it "Get events for section" do
|
86
|
+
events = Osm::Event.get_for_section(@api, 1)
|
87
|
+
events.size.should == 1
|
88
|
+
event = events[0]
|
89
|
+
event.id.should == 2
|
90
|
+
event.section_id.should == 1
|
91
|
+
event.name.should == 'An Event'
|
92
|
+
event.start.should == Date.new(2001, 2, 3)
|
93
|
+
event.finish.should == DateTime.new(2001, 2, 5, 12, 0, 0)
|
94
|
+
event.cost.should == '0.00'
|
95
|
+
event.location.should == 'Somewhere'
|
96
|
+
event.notes.should == 'Notes'
|
97
|
+
event.archived.should be_false
|
98
|
+
event.valid?.should be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "Fetch events for a section honoring archived option" do
|
102
|
+
body = {
|
103
|
+
'identifier' => 'eventid',
|
104
|
+
'label' => 'name',
|
105
|
+
'items' => [{
|
106
|
+
'eventid' => '1',
|
107
|
+
'name' => 'An Event',
|
108
|
+
'startdate' => '2001-02-03',
|
109
|
+
'enddate' => nil,
|
110
|
+
'starttime' => '00:00:00',
|
111
|
+
'endtime' => '00:00:00',
|
112
|
+
'cost' => '0.00',
|
113
|
+
'location' => '',
|
114
|
+
'notes' => '',
|
115
|
+
'sectionid' => 1,
|
116
|
+
'googlecalendar' => nil,
|
117
|
+
'archived' => '0'
|
118
|
+
},{
|
119
|
+
'eventid' => '2',
|
120
|
+
'name' => 'An Archived Event',
|
121
|
+
'startdate' => '2001-02-03',
|
122
|
+
'enddate' => nil,
|
123
|
+
'starttime' => '00:00:00',
|
124
|
+
'endtime' => '00:00:00',
|
125
|
+
'cost' => '0.00',
|
126
|
+
'location' => '',
|
127
|
+
'notes' => '',
|
128
|
+
'sectionid' => 1,
|
129
|
+
'googlecalendar' => nil,
|
130
|
+
'archived' => '1'
|
131
|
+
}]
|
132
|
+
}
|
133
|
+
|
134
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1&showArchived=true", :body => body.to_json)
|
135
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvent§ionid=1&eventid=1", :body => {'config' => '[]'}.to_json)
|
136
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvent§ionid=1&eventid=2", :body => {'config' => '[]'}.to_json)
|
137
|
+
Osm::Event.get_for_section(@api, 1).size.should == 1
|
138
|
+
Osm::Event.get_for_section(@api, 1, {:include_archived => true}).size.should == 2
|
139
|
+
end
|
140
|
+
|
141
|
+
it "Get event" do
|
142
|
+
event = Osm::Event.get(@api, 1, 2)
|
143
|
+
event.should_not be_nil
|
144
|
+
event.id.should == 2
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
it "Create (succeded)" do
|
149
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent§ionid=1'
|
150
|
+
post_data = {
|
151
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
152
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
153
|
+
'userid' => 'user_id',
|
154
|
+
'secret' => 'secret',
|
155
|
+
'name' => 'Test event',
|
156
|
+
'startdate' => '2000-01-02',
|
157
|
+
'enddate' => '2001-02-03',
|
158
|
+
'starttime' => '03:04:05',
|
159
|
+
'endtime' => '04:05:06',
|
160
|
+
'cost' => '1.23',
|
161
|
+
'location' => 'Somewhere',
|
162
|
+
'notes' => 'none'
|
163
|
+
}
|
164
|
+
|
165
|
+
Osm::Event.stub(:get_for_section) { [] }
|
166
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
|
167
|
+
|
168
|
+
event = Osm::Event.create(@api, {
|
169
|
+
:section_id => 1,
|
170
|
+
:name => 'Test event',
|
171
|
+
:start => DateTime.new(2000, 01, 02, 03, 04, 05),
|
172
|
+
:finish => DateTime.new(2001, 02, 03, 04, 05, 06),
|
173
|
+
:cost => '1.23',
|
174
|
+
:location => 'Somewhere',
|
175
|
+
:notes => 'none',
|
176
|
+
:fields => {},
|
177
|
+
})
|
178
|
+
event.should_not be_nil
|
179
|
+
event.id.should == 2
|
180
|
+
end
|
181
|
+
|
182
|
+
it "Create (failed)" do
|
183
|
+
Osm::Event.stub(:get_for_section) { [] }
|
184
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
|
185
|
+
|
186
|
+
event = Osm::Event.create(@api, {
|
187
|
+
:section_id => 1,
|
188
|
+
:name => 'Test event',
|
189
|
+
:start => DateTime.new(2000, 01, 02, 03, 04, 05),
|
190
|
+
:finish => DateTime.new(2001, 02, 03, 04, 05, 06),
|
191
|
+
:cost => '1.23',
|
192
|
+
:location => 'Somewhere',
|
193
|
+
:notes => 'none',
|
194
|
+
:fields => {},
|
195
|
+
})
|
196
|
+
event.should be_nil
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
it "Update (succeded)" do
|
201
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addEvent§ionid=1'
|
202
|
+
post_data = {
|
203
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
204
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
205
|
+
'userid' => 'user_id',
|
206
|
+
'secret' => 'secret',
|
207
|
+
'name' => 'Test event',
|
208
|
+
'startdate' => '2000-01-02',
|
209
|
+
'enddate' => '2001-02-03',
|
210
|
+
'starttime' => '03:04:05',
|
211
|
+
'endtime' => '04:05:06',
|
212
|
+
'cost' => '1.23',
|
213
|
+
'location' => 'Somewhere',
|
214
|
+
'notes' => 'none',
|
215
|
+
'eventid' => 2
|
216
|
+
}
|
217
|
+
|
218
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"id":2}'}) }
|
219
|
+
|
220
|
+
event = Osm::Event.new(
|
221
|
+
:section_id => 1,
|
222
|
+
:name => 'Test event',
|
223
|
+
:start => DateTime.new(2000, 01, 02, 03, 04, 05),
|
224
|
+
:finish => DateTime.new(2001, 02, 03, 04, 05, 06),
|
225
|
+
:cost => '1.23',
|
226
|
+
:location => 'Somewhere',
|
227
|
+
:notes => 'none',
|
228
|
+
:id => 2
|
229
|
+
)
|
230
|
+
event.update(@api).should be_true
|
231
|
+
end
|
232
|
+
|
233
|
+
it "Update (failed)" do
|
234
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
|
235
|
+
|
236
|
+
event = Osm::Event.new(
|
237
|
+
:section_id => 1,
|
238
|
+
:name => 'Test event',
|
239
|
+
:start => DateTime.new(2000, 01, 02, 03, 04, 05),
|
240
|
+
:finish => DateTime.new(2001, 02, 03, 04, 05, 06),
|
241
|
+
:cost => '1.23',
|
242
|
+
:location => 'Somewhere',
|
243
|
+
:notes => 'none',
|
244
|
+
:id => 2
|
245
|
+
)
|
246
|
+
event.update(@api).should be_false
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
it "Delete (succeded)" do
|
251
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=deleteEvent§ionid=1&eventid=2'
|
252
|
+
post_data = {
|
253
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
254
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
255
|
+
'userid' => 'user_id',
|
256
|
+
'secret' => 'secret',
|
257
|
+
}
|
258
|
+
|
259
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"ok":true}'}) }
|
260
|
+
|
261
|
+
event = Osm::Event.new(
|
262
|
+
:section_id => 1,
|
263
|
+
:name => 'Test event',
|
264
|
+
:start => DateTime.new(2000, 01, 02, 03, 04, 05),
|
265
|
+
:finish => DateTime.new(2001, 02, 03, 04, 05, 06),
|
266
|
+
:cost => '1.23',
|
267
|
+
:location => 'Somewhere',
|
268
|
+
:notes => 'none',
|
269
|
+
:id => 2
|
270
|
+
)
|
271
|
+
event.delete(@api).should be_true
|
272
|
+
end
|
273
|
+
|
274
|
+
it "Delete (failed)" do
|
275
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"ok":false}'}) }
|
276
|
+
|
277
|
+
event = Osm::Event.new(
|
278
|
+
:section_id => 1,
|
279
|
+
:name => 'Test event',
|
280
|
+
:start => DateTime.new(2000, 01, 02, 03, 04, 05),
|
281
|
+
:finish => DateTime.new(2001, 02, 03, 04, 05, 06),
|
282
|
+
:cost => '1.23',
|
283
|
+
:location => 'Somewhere',
|
284
|
+
:notes => 'none',
|
285
|
+
:id => 2
|
286
|
+
)
|
287
|
+
event.delete(@api).should be_false
|
288
|
+
end
|
289
|
+
|
290
|
+
|
291
|
+
it "Get attendance" do
|
292
|
+
attendance_body = {
|
293
|
+
'identifier' => 'scoutid',
|
294
|
+
'eventid' => '2',
|
295
|
+
'items' => [
|
296
|
+
{
|
297
|
+
'scoutid' => '1',
|
298
|
+
'attending' => 'Yes',
|
299
|
+
'firstname' => 'First',
|
300
|
+
'lastname' => 'Last',
|
301
|
+
'dob' => '1980-01-02',
|
302
|
+
'patrolid' => '2',
|
303
|
+
'f_1' => 'a',
|
304
|
+
}
|
305
|
+
]
|
306
|
+
}
|
307
|
+
|
308
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEventAttendance&eventid=2§ionid=1&termid=3", :body => attendance_body.to_json)
|
309
|
+
|
310
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
311
|
+
event.should_not be_nil
|
312
|
+
attendance = event.get_attendance(@api, 3)
|
313
|
+
attendance.is_a?(Array).should be_true
|
314
|
+
ea = attendance[0]
|
315
|
+
ea.member_id.should == 1
|
316
|
+
ea.grouping_id.should == 2
|
317
|
+
ea.fields.should == {
|
318
|
+
'firstname' => 'First',
|
319
|
+
'lastname' => 'Last',
|
320
|
+
'dob' => Date.new(1980, 1, 2),
|
321
|
+
'attending' => true,
|
322
|
+
'f_1' => 'a',
|
323
|
+
}
|
324
|
+
ea.row.should == 0
|
325
|
+
end
|
326
|
+
|
327
|
+
it "Update attendance (succeded)" do
|
328
|
+
ea = Osm::Event::Attendance.new(:row => 0, :member_id => 4, :fields => {'f_1' => 'TEST'}, :event => Osm::Event.new(:id => 2, :section_id => 1))
|
329
|
+
|
330
|
+
HTTParty.should_receive(:post).with(
|
331
|
+
"https://www.onlinescoutmanager.co.uk/events.php?action=updateScout",
|
332
|
+
{:body => {
|
333
|
+
'scoutid' => 4,
|
334
|
+
'column' => 'f_1',
|
335
|
+
'value' => 'TEST',
|
336
|
+
'sectionid' => 1,
|
337
|
+
'row' => 0,
|
338
|
+
'eventid' => 2,
|
339
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
340
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
341
|
+
'userid' => 'user_id',
|
342
|
+
'secret' => 'secret',
|
343
|
+
}}
|
344
|
+
) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
|
345
|
+
|
346
|
+
ea.update(@api, 'f_1').should be_true
|
347
|
+
end
|
348
|
+
|
349
|
+
|
350
|
+
it "Add field (succeded)" do
|
351
|
+
url = 'https://www.onlinescoutmanager.co.uk/events.php?action=addColumn§ionid=1&eventid=2'
|
352
|
+
post_data = {
|
353
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
354
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
355
|
+
'userid' => 'user_id',
|
356
|
+
'secret' => 'secret',
|
357
|
+
'columnName' => 'Test field',
|
358
|
+
}
|
359
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"eventid":"2"}'}) }
|
360
|
+
|
361
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
362
|
+
event.should_not be_nil
|
363
|
+
event.add_field(@api, 'Test field').should be_true
|
364
|
+
end
|
365
|
+
|
366
|
+
it "Add field (failed)" do
|
367
|
+
HTTParty.should_receive(:post) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{}'}) }
|
368
|
+
|
369
|
+
event = Osm::Event.new(:id => 2, :section_id => 1)
|
370
|
+
event.should_not be_nil
|
371
|
+
event.add_field(@api, 'Test field').should be_false
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
|
377
|
+
describe "API Strangeness" do
|
378
|
+
it "handles a non existant array when no events" do
|
379
|
+
data = '{"identifier":"eventid","label":"name"}'
|
380
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1&showArchived=true", :body => data)
|
381
|
+
events = Osm::Event.get_for_section(@api, 1).should == []
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
35
385
|
end
|