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
@@ -1,51 +0,0 @@
|
|
1
|
-
module Osm
|
2
|
-
|
3
|
-
class FlexiRecordData
|
4
|
-
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
-
include ::ActiveAttr::Model
|
6
|
-
|
7
|
-
# @!attribute [rw] member_id
|
8
|
-
# @return [Fixnum] OSM id for the member
|
9
|
-
# @!attribute [rw] grouping__id
|
10
|
-
# @return [Fixnum] OSM id for the grouping the member is in
|
11
|
-
# @!attribute [rw] fields
|
12
|
-
# @return [Hash] Keys are the field's id, values are the field values
|
13
|
-
|
14
|
-
attribute :member_id, :type => Integer
|
15
|
-
attribute :grouping_id, :type => Integer
|
16
|
-
attribute :fields, :default => {}
|
17
|
-
|
18
|
-
attr_accessible :member_id, :grouping_id, :fields
|
19
|
-
|
20
|
-
validates_numericality_of :member_id, :only_integer=>true, :greater_than=>0
|
21
|
-
validates_numericality_of :grouping_id, :only_integer=>true, :greater_than_or_equal_to=>-2
|
22
|
-
validates :fields, :hash => {:key_type => String}
|
23
|
-
|
24
|
-
|
25
|
-
# @!method initialize
|
26
|
-
# Initialize a new FlexiRecordData
|
27
|
-
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
28
|
-
|
29
|
-
|
30
|
-
# Initialize a new FlexiRecordData from api data
|
31
|
-
# @param [Hash] data the hash of data provided by the API
|
32
|
-
def self.from_api(data)
|
33
|
-
data.merge!({
|
34
|
-
'dob' => data['dob'].nil? ? nil : Osm::parse_date(data['dob'], :ignore_epoch => true),
|
35
|
-
'total' => Osm::to_i_or_nil(data['total'].eql?('') ? nil : data['total']),
|
36
|
-
'completed' => Osm::to_i_or_nil(data['completed'].eql?('') ? nil : data['completed']),
|
37
|
-
'age' => data['age'].eql?('') ? nil : data['age'],
|
38
|
-
})
|
39
|
-
|
40
|
-
new({
|
41
|
-
:member_id => Osm::to_i_or_nil(data['scoutid']),
|
42
|
-
:grouping_id => Osm::to_i_or_nil(data['patrolid'].eql?('') ? nil : data['patrolid']),
|
43
|
-
:fields => data.select { |key, value|
|
44
|
-
['firstname', 'lastname', 'dob', 'total', 'completed', 'age'].include?(key) || key.to_s.match(/\Af_\d+\Z/)
|
45
|
-
}
|
46
|
-
})
|
47
|
-
end
|
48
|
-
|
49
|
-
end # Class FlexiRecordData
|
50
|
-
|
51
|
-
end # Module
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Osm
|
2
|
-
|
3
|
-
class FlexiRecordField
|
4
|
-
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
-
include ::ActiveAttr::Model
|
6
|
-
|
7
|
-
# @!attribute [rw] id
|
8
|
-
# @return [String] OSM identifier for the field. Special ones are 'dob', 'total', 'completed', 'age', 'firstname' and 'lastname', user ones are of the format 'f\_NUMBER'
|
9
|
-
# @!attribute [rw] name
|
10
|
-
# @return [String] Human readable name for the field
|
11
|
-
# @!attribute [rw] editable
|
12
|
-
# @return [Boolean] Wether the field can be edited
|
13
|
-
|
14
|
-
attribute :id, :type => String
|
15
|
-
attribute :name, :type => String
|
16
|
-
attribute :editable, :type => Boolean, :default => false
|
17
|
-
|
18
|
-
attr_accessible :id, :name, :editable
|
19
|
-
|
20
|
-
validates_presence_of :id
|
21
|
-
validates_presence_of :name
|
22
|
-
validates_inclusion_of :editable, :in => [true, false]
|
23
|
-
|
24
|
-
|
25
|
-
# @!method initialize
|
26
|
-
# Initialize a new FlexiRecordField
|
27
|
-
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
28
|
-
|
29
|
-
|
30
|
-
# Initialize a new FlexiRecordField from api data
|
31
|
-
# @param [Hash] data the hash of data provided by the API
|
32
|
-
def self.from_api(data)
|
33
|
-
new({
|
34
|
-
:id => data['field'],
|
35
|
-
:name => data['name'],
|
36
|
-
:editable => data['editable'],
|
37
|
-
})
|
38
|
-
end
|
39
|
-
|
40
|
-
end # Class FlexiRecordField
|
41
|
-
|
42
|
-
end # Module
|
data/lib/osm/register_data.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Osm
|
2
|
-
|
3
|
-
class RegisterData
|
4
|
-
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
-
include ::ActiveAttr::Model
|
6
|
-
|
7
|
-
# @!attribute [rw] member_id
|
8
|
-
# @return [Fixnum] The OSM ID for the member
|
9
|
-
# @!attribute [rw] grouping_id
|
10
|
-
# @return [Fixnum] The OSM ID for the member's grouping
|
11
|
-
# @!attribute [rw] section_id
|
12
|
-
# @return [Fixnum] The OSM ID for the member's section
|
13
|
-
# @!attribute [rw] first_name
|
14
|
-
# @return [String] The member's first name
|
15
|
-
# @!attribute [rw] last_name
|
16
|
-
# @return [String] The member's last name
|
17
|
-
# @!attribute [rw] total
|
18
|
-
# @return [FixNum] Total
|
19
|
-
# @!attribute [rw] attendance
|
20
|
-
# @return [Hash] The data for each field - keys are the date, values one of 'Yes' (present), 'No' (known absence) or nil (absent)
|
21
|
-
|
22
|
-
attribute :member_id, :type => Integer
|
23
|
-
attribute :grouping_id, :type => Integer
|
24
|
-
attribute :section_id, :type => Integer
|
25
|
-
attribute :first_name, :type => String
|
26
|
-
attribute :last_name, :type => String
|
27
|
-
attribute :total, :type => Integer
|
28
|
-
attribute :attendance, :default => {}
|
29
|
-
|
30
|
-
attr_accessible :member_id, :first_name, :last_name, :section_id, :grouping_id, :total, :attendance
|
31
|
-
|
32
|
-
validates_numericality_of :member_id, :only_integer=>true, :greater_than=>0
|
33
|
-
validates_numericality_of :grouping_id, :only_integer=>true, :greater_than_or_equal_to=>-2
|
34
|
-
validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
|
35
|
-
validates_numericality_of :total, :only_integer=>true, :greater_than_or_equal_to=>0
|
36
|
-
validates_presence_of :first_name
|
37
|
-
validates_presence_of :last_name
|
38
|
-
|
39
|
-
validates :attendance, :hash => {:key_type => Date, :value_in => ['Yes', 'No', nil]}
|
40
|
-
|
41
|
-
|
42
|
-
# @!method initialize
|
43
|
-
# Initialize a new registerData
|
44
|
-
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
45
|
-
|
46
|
-
|
47
|
-
# Initialize a new RegisterData from api data
|
48
|
-
# @param [Hash] data the hash of data provided by the API
|
49
|
-
def self.from_api(data)
|
50
|
-
new(
|
51
|
-
:member_id => Osm::to_i_or_nil(data['scoutid']),
|
52
|
-
:grouping_id => Osm::to_i_or_nil(data['patrolid']),
|
53
|
-
:section_id => Osm::to_i_or_nil(data['sectionid']),
|
54
|
-
:first_name => data['firstname'],
|
55
|
-
:last_name => data['lastname'],
|
56
|
-
:total => data['total'].to_i,
|
57
|
-
:attendance => data.select { |key, value| key.to_s.match(Osm::OSM_DATE_REGEX) }.
|
58
|
-
inject({}){ |new_hash,(date, attendance)| new_hash[Date.strptime(date, Osm::OSM_DATE_FORMAT)] = attendance; new_hash },
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
end # Class RegisterData
|
63
|
-
|
64
|
-
end # Module
|
data/lib/osm/register_field.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module Osm
|
2
|
-
|
3
|
-
class RegisterField
|
4
|
-
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
-
include ::ActiveAttr::Model
|
6
|
-
|
7
|
-
# @!attribute [rw] id
|
8
|
-
# @return [String] OSM identifier for the field
|
9
|
-
# @!attribute [rw] name
|
10
|
-
# @return [String] Human readable name for the field
|
11
|
-
# @!attribute [rw] tooltip
|
12
|
-
# @return [String] Tooltip for the field
|
13
|
-
|
14
|
-
attribute :id, :type => String
|
15
|
-
attribute :name, :type => String
|
16
|
-
attribute :tooltip, :type => String, :default => ''
|
17
|
-
|
18
|
-
attr_accessible :id, :name, :tooltip
|
19
|
-
|
20
|
-
validates_presence_of :id
|
21
|
-
validates_presence_of :name
|
22
|
-
validates_presence_of :tooltip, :allow_blank => true
|
23
|
-
|
24
|
-
|
25
|
-
# @!method initialize
|
26
|
-
# Initialize a new RegisterField
|
27
|
-
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
28
|
-
|
29
|
-
|
30
|
-
# Initialize a new RegisterField from api data
|
31
|
-
# @param [Hash] data the hash of data provided by the API
|
32
|
-
def self.from_api(data)
|
33
|
-
new({
|
34
|
-
:id => data['field'],
|
35
|
-
:name => data['name'],
|
36
|
-
:tooltip => data['tooltip'],
|
37
|
-
})
|
38
|
-
end
|
39
|
-
|
40
|
-
end # Class RegisterField
|
41
|
-
|
42
|
-
end # Module
|
data/lib/osm/role.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module Osm
|
2
|
-
|
3
|
-
class Role
|
4
|
-
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
-
include ::ActiveAttr::Model
|
6
|
-
|
7
|
-
|
8
|
-
# @!attribute [rw] section
|
9
|
-
# @param [Osm::Section] section the section this role is related to
|
10
|
-
# @return [Osm::Section] the section this role related to
|
11
|
-
# @!attribute [rw] group_name
|
12
|
-
# @return [String] the name of the group the section is in
|
13
|
-
# @!attribute [rw] group_id
|
14
|
-
# @return [Fixnum] the group the section is in
|
15
|
-
# @!attribute [rw] permissions
|
16
|
-
# @return [Hash] the permissions the user has in this role
|
17
|
-
|
18
|
-
attribute :section, :type => Object
|
19
|
-
attribute :group_name, :type => String
|
20
|
-
attribute :group_id, :type => Integer
|
21
|
-
attribute :permissions, :default => {}
|
22
|
-
|
23
|
-
attr_accessible :section, :group_name, :group_id, :permissions
|
24
|
-
|
25
|
-
|
26
|
-
validates_presence_of :section
|
27
|
-
validates_numericality_of :group_id, :only_integer=>true, :greater_than=>0
|
28
|
-
validates_presence_of :group_name
|
29
|
-
validates_presence_of :permissions, :unless => Proc.new { |a| a.permissions == {} }
|
30
|
-
|
31
|
-
validates :permissions, :hash => {:key_type => Symbol, :value_in => [10, 20, 100]}
|
32
|
-
|
33
|
-
validates_each :section do |record, attr, value|
|
34
|
-
unless value.nil?
|
35
|
-
record.errors.add(attr, 'must also be valid') unless value.valid?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
# @!method initialize
|
41
|
-
# Initialize a new Role
|
42
|
-
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
43
|
-
|
44
|
-
|
45
|
-
# Initialize a new Role from api data
|
46
|
-
# @param [Hash] data the hash of data provided by the API
|
47
|
-
def self.from_api(data)
|
48
|
-
attributes = {}
|
49
|
-
attributes[:group_name] = data['groupname']
|
50
|
-
attributes[:group_id] = Osm::to_i_or_nil(data['groupid'])
|
51
|
-
|
52
|
-
# Convert permission values to a number
|
53
|
-
permissions = data['permissions'].is_a?(Hash) ? Osm::symbolize_hash(data['permissions']) : {}
|
54
|
-
permissions.each_key do |key|
|
55
|
-
permissions[key] = permissions[key].to_i
|
56
|
-
end
|
57
|
-
|
58
|
-
role = new(attributes.merge(:permissions => permissions))
|
59
|
-
role.section = Osm::Section.from_api(data['sectionid'], data['sectionname'], ActiveSupport::JSON.decode(data['sectionConfig']), role)
|
60
|
-
|
61
|
-
return role
|
62
|
-
end
|
63
|
-
|
64
|
-
# Determine if this role has read access for the provided permission
|
65
|
-
# @param [Symbol] key the permission being queried
|
66
|
-
# @return [Boolean] if this role can read the passed permission
|
67
|
-
def can_read?(key)
|
68
|
-
return [10, 20, 100].include?(permissions[key])
|
69
|
-
end
|
70
|
-
|
71
|
-
# Determine if this role has write access for the provided permission
|
72
|
-
# @param [Symbol] key the permission being queried
|
73
|
-
# @return [Boolean] if this role can write the passed permission
|
74
|
-
def can_write?(key)
|
75
|
-
return [20, 100].include?(permissions[key])
|
76
|
-
end
|
77
|
-
|
78
|
-
# Get section's long name in a consistent format
|
79
|
-
# @return [String] e.g. "Scouts (1st Somewhere)"
|
80
|
-
def long_name
|
81
|
-
group_name.blank? ? section.name : "#{section.name} (#{group_name})"
|
82
|
-
end
|
83
|
-
|
84
|
-
# Get section's full name in a consistent format
|
85
|
-
# @return [String] e.g. "1st Somewhere Beavers"
|
86
|
-
def full_name
|
87
|
-
group_name.blank? ? section.name : "#{group_name} #{section.name}"
|
88
|
-
end
|
89
|
-
|
90
|
-
def <=>(another_role)
|
91
|
-
begin
|
92
|
-
compare_group_name = group_name <=> another_role.group_name
|
93
|
-
return compare_group_name unless compare_group_name == 0
|
94
|
-
|
95
|
-
return 0 if section.type == another_role.section.type
|
96
|
-
[:beavers, :cubs, :scouts, :explorers, :waiting, :adults].each do |type|
|
97
|
-
return -1 if section.type == type
|
98
|
-
return 1 if another_role.section.type == type
|
99
|
-
end
|
100
|
-
rescue NoMethodError
|
101
|
-
return false
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def ==(another_role)
|
106
|
-
begin
|
107
|
-
return section == another_role.section
|
108
|
-
rescue NoMethodError
|
109
|
-
return false
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def inspect
|
114
|
-
attribute_descriptions = attributes.merge('section' => (section.nil? ? nil : section.inspect_without_role(self)))
|
115
|
-
return_inspect(attribute_descriptions)
|
116
|
-
end
|
117
|
-
|
118
|
-
def inspect_without_section(exclude_section)
|
119
|
-
attribute_descriptions = (section == exclude_section) ? attributes.merge('section' => 'SET') : attributes
|
120
|
-
return_inspect(attribute_descriptions)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
private
|
125
|
-
def return_inspect(attribute_descriptions)
|
126
|
-
attribute_descriptions.sort.map { |key, value| "#{key}: #{key.eql?('section') ? value : value.inspect}" }.join(", ")
|
127
|
-
separator = " " unless attribute_descriptions.empty?
|
128
|
-
"#<#{self.class.name}#{separator}#{attribute_descriptions}>"
|
129
|
-
end
|
130
|
-
|
131
|
-
end # Class Role
|
132
|
-
|
133
|
-
end # Module
|
@@ -1,83 +0,0 @@
|
|
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§ion=cubs§ionid=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§ionid=1&showArchived=true", :body => data)
|
44
|
-
|
45
|
-
@api.get_events(1).should == []
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
it "handles a section config where fields is an empty array" do
|
50
|
-
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}}]'
|
51
|
-
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
|
52
|
-
|
53
|
-
@api.get_section(1).fields.should == {}
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
it "handles a section's flexi records being a hash" do
|
58
|
-
data = {
|
59
|
-
'subscription_level' => '3',
|
60
|
-
'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
|
61
|
-
'sectionType' => 'cubs',
|
62
|
-
'numscouts' => 10,
|
63
|
-
'columnNames' => {},
|
64
|
-
'fields' => {},
|
65
|
-
'intouch' => {},
|
66
|
-
'mobFields' => {},
|
67
|
-
'extraRecords' => {
|
68
|
-
'1' => {
|
69
|
-
'name' => 'Name 1',
|
70
|
-
'extraid' => 1
|
71
|
-
},
|
72
|
-
'2' => {
|
73
|
-
'name' => 'Name 2',
|
74
|
-
'extraid' => 2
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
section = Osm::Section.from_api(1, 'Name', data, nil)
|
79
|
-
section.flexi_records.size.should == 2
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'date'
|
4
|
-
|
5
|
-
|
6
|
-
describe "Event Attendance" do
|
7
|
-
|
8
|
-
it "Create from API data" do
|
9
|
-
data = {
|
10
|
-
"scoutid" => "1",
|
11
|
-
"firstname" => "First",
|
12
|
-
"lastname" => "Last",
|
13
|
-
"dob" => "1899-11-30",
|
14
|
-
"patrolid" => "2",
|
15
|
-
"f_1" => "a",
|
16
|
-
"attending" => "Yes",
|
17
|
-
}
|
18
|
-
|
19
|
-
ea = Osm::EventAttendance.from_api(data, 3)
|
20
|
-
|
21
|
-
ea.member_id.should == 1
|
22
|
-
ea.grouping_id.should == 2
|
23
|
-
ea.fields.should == {
|
24
|
-
'firstname' => 'First',
|
25
|
-
'lastname' => 'Last',
|
26
|
-
'dob' => Date.new(1899, 11, 30),
|
27
|
-
'attending' => true,
|
28
|
-
'f_1' => 'a',
|
29
|
-
}
|
30
|
-
ea.row.should == 3
|
31
|
-
ea.valid?.should be_true
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|