osm 1.0.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/osm/model.rb CHANGED
@@ -159,7 +159,7 @@ module Osm
159
159
 
160
160
  # Raise an exception if the user does not have the relevant permission
161
161
  # @param [Osm::Api] api The api to use to make the request
162
- # @param [Symbol] level The OSM subscription level required (e.g. :gold)
162
+ # @param [Symbol] level The OSM subscription level required (:bronze, :silver, :gold, :gold_plus)
163
163
  # @param [Osm::Section, Fixnum, #to_i] section The Section (or its ID) the subscription is required on
164
164
  # @!macro options_get
165
165
  # @raise [Osm::Forbidden] If the Section does not have the required OSM Subscription (or higher)
@@ -173,12 +173,14 @@ module Osm
173
173
  level = 2
174
174
  when :gold
175
175
  level = 3
176
+ when :gold_plus
177
+ level = 4
176
178
  else
177
179
  level = 0
178
180
  end
179
181
  end
180
182
  if section.nil? || section.subscription_level < level
181
- level_name = ['Unknown', 'Bronze', 'Silver', 'Gold'][level] || level
183
+ level_name = Osm::SUBSCRIPTION_LEVEL_NAMES[level] || level
182
184
  raise Osm::Forbidden, "Insufficent OSM subscription level (#{level_name} required for #{section.name})"
183
185
  end
184
186
  end
data/lib/osm/register.rb CHANGED
@@ -22,15 +22,14 @@ module Osm
22
22
 
23
23
  structure = []
24
24
  if data.is_a?(Array)
25
- data.each do |item|
26
- if item.is_a?(Hash) && item['rows'].is_a?(Array)
27
- item['rows'].each do |row|
28
- structure.push Field.new(
29
- :id => row['field'],
30
- :name => row['name'],
31
- :tooltip => row['tooltip'],
32
- )
33
- end
25
+ data = (data.size == 2) ? data[1] : []
26
+ if data.is_a?(Hash) && data['rows'].is_a?(Array)
27
+ data['rows'].each do |row|
28
+ structure.push Field.new(
29
+ :id => row['field'],
30
+ :name => row['name'],
31
+ :tooltip => row['tooltip'],
32
+ )
34
33
  end
35
34
  end
36
35
  end
@@ -57,7 +56,7 @@ module Osm
57
56
 
58
57
  data = api.perform_query("users.php?action=register&sectionid=#{section_id}&termid=#{term_id}")
59
58
  dates_s = get_structure(api, section, term, options)
60
- dates_s = dates_s.map{ |f| f.id }.select{ |f| f.match(Osm::OSM_DATE_REGEX) }
59
+ dates_s = dates_s.map{ |f| f.id }
61
60
  dates_d = dates_s.map{ |d| Osm::parse_date(d) }
62
61
 
63
62
  to_return = []
@@ -73,7 +72,6 @@ module Osm
73
72
  attendance[date] = :yes if item_attendance.eql?('Yes')
74
73
  attendance[date] = :advised_absent if item_attendance.eql?('No')
75
74
  end
76
- item.select{}
77
75
  to_return.push Osm::Register::Attendance.new(
78
76
  :member_id => Osm::to_i_or_nil(item['scoutid']),
79
77
  :grouping_id => Osm::to_i_or_nil(item ['patrolid']),
data/lib/osm/section.rb CHANGED
@@ -10,7 +10,7 @@ module Osm
10
10
  # @!attribute [rw] group_name
11
11
  # @return [String] the group name
12
12
  # @!attribute [rw] subscription_level
13
- # @return [Fixnum] what subscription the section has to OSM (1-bronze, 2-silver, 3-gold)
13
+ # @return [Fixnum] what subscription the section has to OSM (1-bronze, 2-silver, 3-gold, 4-gold+)
14
14
  # @!attribute [rw] subscription_expires
15
15
  # @return [Date] when the section's subscription to OSM expires
16
16
  # @!attribute [rw] type
@@ -33,14 +33,18 @@ module Osm
33
33
  # @return [Date] when the subscription to Badges in My.SCOUT expires
34
34
  # @!attribute [rw] myscout_programme_expires
35
35
  # @return [Date] when the subscription to Badges in My.SCOUT expires
36
- # @!attribute [rw] myscout_events
37
- # @return [Boolean] whether the section uses the Events part of My.SCOUT
36
+ # @!attribute [rw] myscout_events_expires
37
+ # @return [Date] when the subscription to Events in My.SCOUT expires
38
+ # @!attribute [rw] myscout_details_expires
39
+ # @return [Boolean] whether the section uses the Personal Details part of My.SCOUT
38
40
  # @!attribute [rw] myscout_badges
39
41
  # @return [Boolean] whether the section uses the Badges part of My.SCOUT
40
42
  # @!attribute [rw] myscout_programme
41
43
  # @return [Boolean] whether the section uses the Programme part of My.SCOUT
42
44
  # @!attribute [rw] myscout_payments
43
45
  # @return [Boolean] whether the section uses the Payments part of My.SCOUT
46
+ # @!attribute [rw] myscout_details
47
+ # @return [Boolean] whether the section uses the Personal Details part of My.SCOUT
44
48
  # @!attribute [rw] myscout_emails
45
49
  # @return [Hash of Symbol to Boolean] which email addresses are linked to MyScout for each Member
46
50
  # @!attribute [rw] myscout_email_address_from
@@ -52,7 +56,9 @@ module Osm
52
56
  # @!attribute [rw] myscout_programme_summary
53
57
  # @return [Boolean] Wether parents can see summary of programme items
54
58
  # @!attribute [rw] myscout_programme_times
55
- # @return [Boolean] Wether parents can see times of programme items
59
+ # @return [Boolean] Whether parents can see times of programme items
60
+ # @!attribute [rw] myscout_programme_show
61
+ # @return [Fixnum] How many programme itemms parents can see (the next 5, 10, 15, 20 meetings, -1 (whole term), 0 (remaining this term) or -2 (all future))
56
62
  # @!attribute [rw] myscout_event_reminder_count
57
63
  # @return [Fixnum] How many event reminders to send to parents who haven't responded
58
64
  # @!attribute [rw] myscout_event_reminder_frequency
@@ -61,6 +67,8 @@ module Osm
61
67
  # @return [Fixnum] How many payment reminders to send to parents who haven't paid yet
62
68
  # @!attribute [rw] myscout_payment_reminder_frequency
63
69
  # @return [Fixnum] How many days to leave between payment reminder emails
70
+ # @!attribute [rw] myscout_details_email_changes_to
71
+ # @return [String] email address to send changes to personal details made through My.SCOUT to
64
72
  # @!attribute [rw] sms_sent_test
65
73
  # @return [Boolean] Whether the section has sent their test SMS message
66
74
  # @!attribute [rw] sms_messages_sent
@@ -84,20 +92,24 @@ module Osm
84
92
  attribute :myscout_events_expires, :type => Date
85
93
  attribute :myscout_badges_expires, :type => Date
86
94
  attribute :myscout_programme_expires, :type => Date
95
+ attribute :myscout_details_expires, :type => Date
87
96
  attribute :myscout_events, :type => Boolean
88
97
  attribute :myscout_badges, :type => Boolean
89
98
  attribute :myscout_programme, :type => Boolean
90
99
  attribute :myscout_payments, :type => Boolean
100
+ attribute :myscout_details, :type => Boolean
91
101
  attribute :myscout_emails, :default => {}
92
102
  attribute :myscout_email_address_from, :type => String, :default => ''
93
103
  attribute :myscout_email_address_copy, :type => String, :default => ''
94
104
  attribute :myscout_badges_partial, :type => Boolean
95
105
  attribute :myscout_programme_summary, :type => Boolean
96
106
  attribute :myscout_programme_times, :type => Boolean
107
+ attribute :myscout_programme_show, :type => Integer, :default => 0
97
108
  attribute :myscout_event_reminder_count, :type => Integer
98
109
  attribute :myscout_event_reminder_frequency, :type => Integer
99
110
  attribute :myscout_payment_reminder_count, :type => Integer
100
111
  attribute :myscout_payment_reminder_frequency, :type => Integer
112
+ attribute :myscout_details_email_changes_to, :type => String, :default => ''
101
113
  attribute :sms_sent_test, :type => Boolean, :default => false
102
114
  attribute :sms_messages_sent, :type => Integer, :default => 0
103
115
  attribute :sms_messages_remaining, :type => Integer, :default => 0
@@ -105,12 +117,13 @@ module Osm
105
117
  attr_accessible :id, :name, :group_id, :group_name, :subscription_level, :subscription_expires,
106
118
  :type, :column_names, :fields, :intouch_fields, :mobile_fields, :flexi_records,
107
119
  :gocardless, :myscout_events_expires, :myscout_badges_expires,
108
- :myscout_programme_expires, :myscout_events, :myscout_badges,
109
- :myscout_programme, :myscout_payments, :myscout_emails,
110
- :myscout_email_address_from, :myscout_email_address_copy,
120
+ :myscout_programme_expires, :myscout_details_expires, :myscout_events,
121
+ :myscout_badges, :myscout_programme, :myscout_payments, :myscout_details,
122
+ :myscout_emails, :myscout_email_address_from, :myscout_email_address_copy,
111
123
  :myscout_badges_partial, :myscout_programme_summary, :myscout_programme_times,
112
- :myscout_event_reminder_count, :myscout_event_reminder_frequency,
113
- :myscout_payment_reminder_count, :myscout_payment_reminder_frequency,
124
+ :myscout_programme_show, :myscout_event_reminder_count,
125
+ :myscout_event_reminder_frequency, :myscout_payment_reminder_count,
126
+ :myscout_payment_reminder_frequency, :myscout_details_email_changes_to,
114
127
  :sms_sent_test, :sms_messages_sent, :sms_messages_remaining
115
128
 
116
129
  validates_numericality_of :id, :only_integer=>true, :greater_than=>0, :allow_nil => true
@@ -127,11 +140,11 @@ module Osm
127
140
  validates_presence_of :subscription_level
128
141
  validates_presence_of :subscription_expires
129
142
  validates_presence_of :type
130
- validates_presence_of :column_names, :unless => Proc.new { |a| a.column_names == {} }
131
- validates_presence_of :fields, :unless => Proc.new { |a| a.fields == {} }
132
- validates_presence_of :intouch_fields, :unless => Proc.new { |a| a.intouch_fields == {} }
133
- validates_presence_of :mobile_fields, :unless => Proc.new { |a| a.mobile_fields == {} }
134
- validates_presence_of :flexi_records, :unless => Proc.new { |a| a.flexi_records == [] }
143
+ # validates_presence_of :column_names, :unless => Proc.new { |a| a.column_names == {} }
144
+ # validates_presence_of :fields, :unless => Proc.new { |a| a.fields == {} }
145
+ # validates_presence_of :intouch_fields, :unless => Proc.new { |a| a.intouch_fields == {} }
146
+ # validates_presence_of :mobile_fields, :unless => Proc.new { |a| a.mobile_fields == {} }
147
+ # validates_presence_of :flexi_records, :unless => Proc.new { |a| a.flexi_records == [] }
135
148
 
136
149
  validates_inclusion_of :subscription_level, :in => (1..3), :message => 'is not a valid subscription level'
137
150
  validates_inclusion_of :gocardless, :in => [true, false]
@@ -139,9 +152,11 @@ module Osm
139
152
  validates_inclusion_of :myscout_badges, :in => [true, false]
140
153
  validates_inclusion_of :myscout_programme, :in => [true, false]
141
154
  validates_inclusion_of :myscout_payments, :in => [true, false]
155
+ validates_inclusion_of :myscout_details, :in => [true, false]
142
156
  validates_inclusion_of :myscout_badges_partial, :in => [true, false]
143
157
  validates_inclusion_of :myscout_programme_summary, :in => [true, false]
144
158
  validates_inclusion_of :myscout_programme_times, :in => [true, false]
159
+ validates_inclusion_of :myscout_programme_show, :in => [-2, -1, 0, 5, 10, 15, 20]
145
160
  validates_inclusion_of :sms_sent_test, :in => [true, false]
146
161
 
147
162
  validates :column_names, :hash => {:key_type => Symbol, :value_type => String}
@@ -215,20 +230,24 @@ module Osm
215
230
  :myscout_events_expires => Osm::parse_date(section_data['portalExpires']['events']),
216
231
  :myscout_badges_expires => Osm::parse_date(section_data['portalExpires']['badges']),
217
232
  :myscout_programme_expires => Osm::parse_date(section_data['portalExpires']['programme']),
233
+ :myscout_details_expires => Osm::parse_date(section_data['portalExpires']['details']),
218
234
  :myscout_events => myscout_data['events'] == 1,
219
235
  :myscout_badges => myscout_data['badges'] == 1,
220
236
  :myscout_programme => myscout_data['programme'] == 1,
221
237
  :myscout_payments => myscout_data['payments'] == 1,
238
+ :myscout_details => myscout_data['details'] == 1,
222
239
  :myscout_emails => (myscout_data['emails'] || {}).inject({}) { |n,(k,v)| n[k.to_sym] = v.eql?('true'); n},
223
240
  :myscout_email_address_from => myscout_data['emailAddress'] ? myscout_data['emailAddress'] : '',
224
241
  :myscout_email_address_copy => myscout_data['emailAddressCopy'] ? myscout_data['emailAddressCopy'] : '',
225
242
  :myscout_badges_partial => myscout_data['badgesPartial'] == 1,
226
243
  :myscout_programme_summary => myscout_data['programmeSummary'] == 1,
227
244
  :myscout_programme_times => myscout_data['programmeTimes'] == 1,
245
+ :myscout_programme_show => myscout_data['programmeShow'].to_i,
228
246
  :myscout_event_reminder_count => myscout_data['eventRemindCount'].to_i,
229
247
  :myscout_event_reminder_frequency => myscout_data['eventRemindFrequency'].to_i,
230
248
  :myscout_payment_reminder_count => myscout_data['paymentRemindCount'].to_i,
231
249
  :myscout_payment_reminder_frequency => myscout_data['paymentRemindFrequency'].to_i,
250
+ :myscout_details_email_changes_to => myscout_data['contactNotificationEmail'],
232
251
  :sms_sent_test => section_data['hasSentTestSMS'],
233
252
  :sms_messages_sent => section_data['sms_sent'],
234
253
  :sms_messages_remaining => section_data['sms_remaining'],
@@ -348,12 +367,10 @@ module Osm
348
367
 
349
368
  # Get the name for the section's subscription level
350
369
  # @return [String, nil] the name of the subscription level (nil if no name exists)
370
+ # @deprecated Please use Osm::SUBSCRIPTION_LEVEL_NAMES[section.subscription_level instead
351
371
  def subscription_level_name
352
- return {
353
- 1 => 'Bronze',
354
- 2 => 'Silver',
355
- 3 => 'Gold',
356
- }[subscription_level]
372
+ warn "[DEPRECATION] `subscription_level_name` is deprecated. Please use `Osm::SUBSCRIPTION_LEVEL_NAMES[section.subscription_level` instead."
373
+ Osm::SUBSCRIPTION_LEVEL_NAMES[subscription_level]
357
374
  end
358
375
 
359
376
  # Compare Section based on group_name type (age order), then name
data/lib/osm/sms.rb CHANGED
@@ -6,19 +6,20 @@ module Osm
6
6
  # @param [Osm::Api] api The api to use to make the request
7
7
  # @param [Osm::Section, Fixnum, #to_i] section The section (or its ID) to send the message to
8
8
  # @param [Array<Osm::Member, Fixnum, #to_i>, Osm::Member, Fixnum, #to_i] members The members (or their IDs) to send the message to
9
- # @param [Symbol] all_or_one Wheather to send the message to all numbers for a member (:all) or just the first mobile one (:one)
9
+ # @param [Symbol, String] mobile_numbers Wheather to send the message to all numbers for a member (:all) or just the first mobile one (:first) or a selection (e.g. "12", "24" etc.)
10
10
  # @param [String, #to_s] source_address The number to claim the message is from
11
11
  # @param [String, #to_s] message The text of the message to send
12
12
  # @return [Hash] with keys :sent (Fixnum), :result (Boolean) and :message (String)
13
- def self.send_sms(api, section, members, all_or_one, source_address, message)
14
- raise ArgumentError, 'all_or_one must be either :all or :one' unless [:all, :one].include?(all_or_one)
15
- Osm::Model.require_access_to_section(api, section)
13
+ def self.send_sms(api, section, members, mobile_numbers, source_address, message)
14
+ raise ArgumentError, 'mobile_numbers must be either :all, :first or a String containing numbers 1-4' unless ([:all, :first, :one].include?(mobile_numbers) || mobile_numbers.match(/[1234]{1,4}/))
15
+ Osm::Model.require_access_to_section(api, section)
16
+ mobile_numbers = :one if mobile_numbers.eql?(:first)
16
17
 
17
18
  data = api.perform_query("sms.php?action=sendText&sectionid=#{section.to_i}", {
18
19
  'msg' => message,
19
20
  'scouts' => [*members].join(','),
20
21
  'source' => source_address,
21
- 'all' => all_or_one,
22
+ 'type' => mobile_numbers,
22
23
  'scheduled' => 'now',
23
24
  })
24
25
 
data/lib/osm/term.rb CHANGED
@@ -104,7 +104,7 @@ module Osm
104
104
  # @param [Osm::Section, Fixnum, #to_i] section The section (or its ID) to get terms for
105
105
  # @!macro options_get
106
106
  # @return [Osm::Term, nil] The current term or nil if the user can not access that section
107
- # @raise [Osm::Error] If the term doesn't have a Term which is current
107
+ # @raise [Osm::Error::NoCurrentTerm] If the Section doesn't have a Term which is current
108
108
  def self.get_current_term_for_section(api, section, options={})
109
109
  section_id = section.to_i
110
110
  terms = get_for_section(api, section_id, options)
@@ -114,7 +114,7 @@ module Osm
114
114
  return term if term.current?
115
115
  end
116
116
 
117
- raise Osm::Error, 'There is no current term for the section.'
117
+ raise Osm::Error::NoCurrentTerm, 'There is no current term for the section.'
118
118
  end
119
119
 
120
120
  # Create a term in OSM
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+
5
+ describe "Budget" do
6
+
7
+ it "Create Budget" do
8
+ b = Osm::Budget.new(
9
+ :id => 1,
10
+ :section_id => 2,
11
+ :name => 'Name',
12
+ )
13
+
14
+ b.id.should == 1
15
+ b.section_id.should == 2
16
+ b.name.should == 'Name'
17
+ b.valid?.should be_true
18
+ end
19
+
20
+ it "Sorts Budget by section ID then name" do
21
+ b1 = Osm::Budget.new(:section_id => 1, :name => 'a')
22
+ b2 = Osm::Budget.new(:section_id => 2, :name => 'a')
23
+ b3 = Osm::Budget.new(:section_id => 2, :name => 'b')
24
+
25
+ data = [b2, b3, b1]
26
+ data.sort.should == [b1, b2, b3]
27
+ end
28
+
29
+
30
+ describe "Using the API" do
31
+
32
+ it "Get budgets for section" do
33
+ data = {
34
+ "identifier" => "categoryid",
35
+ "items" => [
36
+ {
37
+ "categoryid" => "2",
38
+ "sectionid" => "3",
39
+ "name" => "Name",
40
+ "archived" => "1"
41
+ }
42
+ ]
43
+ }
44
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/finances.php?action=getCategories&sectionid=3", :body => data.to_json)
45
+
46
+ budgets = Osm::Budget.get_for_section(@api, 3)
47
+ budgets.should == [Osm::Budget.new(:id => 2, :section_id => 3, :name => 'Name')]
48
+ end
49
+
50
+ it "Create budget (success)" do
51
+ budget = Osm::Budget.new(
52
+ :section_id => 2,
53
+ :name => 'Budget Name',
54
+ )
55
+
56
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=addCategory&sectionid=2"
57
+ HTTParty.should_receive(:post).with(url, :body => {
58
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
59
+ 'token' => @CONFIGURATION[:api][:osm][:token],
60
+ 'userid' => 'user_id',
61
+ 'secret' => 'secret',
62
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
63
+ Osm::Budget.should_receive(:get_for_section).with(@api, 2, {:no_cache=>true}) { [Osm::Budget.new(:id => 3, :section_id => 2, :name => 'Existing budget'), Osm::Budget.new(:id => 4, :section_id => 2, :name => '** Unnamed **')] }
64
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=updateCategory&sectionid=2"
65
+ HTTParty.should_receive(:post).with(url, :body => {
66
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
67
+ 'token' => @CONFIGURATION[:api][:osm][:token],
68
+ 'userid' => 'user_id',
69
+ 'secret' => 'secret',
70
+ 'categoryid' => 4,
71
+ 'column' => 'name',
72
+ 'value' => 'Budget Name',
73
+ 'section_id' => 2,
74
+ 'row' => 0,
75
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
76
+
77
+ budget.create(@api).should be_true
78
+ budget.id.should == 4
79
+ end
80
+
81
+ it "Create budget (failure (not created))" do
82
+ budget = Osm::Budget.new(
83
+ :section_id => 2,
84
+ :name => 'Budget Name',
85
+ )
86
+
87
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=addCategory&sectionid=2"
88
+ HTTParty.should_receive(:post).with(url, :body => {
89
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
90
+ 'token' => @CONFIGURATION[:api][:osm][:token],
91
+ 'userid' => 'user_id',
92
+ 'secret' => 'secret',
93
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
94
+ Osm::Budget.should_receive(:get_for_section).with(@api, 2, {:no_cache=>true}) { [Osm::Budget.new(:id => 3, :section_id => 2, :name => 'Existing budget')] }
95
+
96
+ budget.create(@api).should be_false
97
+ end
98
+
99
+ it "Create budget (failure (not updated))" do
100
+ budget = Osm::Budget.new(
101
+ :section_id => 2,
102
+ :name => 'Budget Name',
103
+ )
104
+
105
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=addCategory&sectionid=2"
106
+ HTTParty.should_receive(:post).with(url, :body => {
107
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
108
+ 'token' => @CONFIGURATION[:api][:osm][:token],
109
+ 'userid' => 'user_id',
110
+ 'secret' => 'secret',
111
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
112
+ Osm::Budget.should_receive(:get_for_section).with(@api, 2, {:no_cache=>true}) { [Osm::Budget.new(:id => 3, :section_id => 2, :name => '** Unnamed **')] }
113
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=updateCategory&sectionid=2"
114
+ HTTParty.should_receive(:post).with(url, :body => {
115
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
116
+ 'token' => @CONFIGURATION[:api][:osm][:token],
117
+ 'userid' => 'user_id',
118
+ 'secret' => 'secret',
119
+ 'categoryid' => 3,
120
+ 'column' => 'name',
121
+ 'value' => 'Budget Name',
122
+ 'section_id' => 2,
123
+ 'row' => 0,
124
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
125
+
126
+ budget.create(@api).should be_false
127
+ end
128
+
129
+ it "Update budget (success)" do
130
+ budget = Osm::Budget.new(
131
+ :id => 1,
132
+ :section_id => 2,
133
+ :name => 'Budget Name',
134
+ )
135
+
136
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=updateCategory&sectionid=2"
137
+ HTTParty.should_receive(:post).with(url, :body => {
138
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
139
+ 'token' => @CONFIGURATION[:api][:osm][:token],
140
+ 'userid' => 'user_id',
141
+ 'secret' => 'secret',
142
+ 'categoryid' => 1,
143
+ 'column' => 'name',
144
+ 'value' => 'Budget Name',
145
+ 'section_id' => 2,
146
+ 'row' => 0,
147
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
148
+
149
+ budget.update(@api).should be_true
150
+ end
151
+
152
+ it "Update budget (failure)" do
153
+ budget = Osm::Budget.new(
154
+ :id => 1,
155
+ :section_id => 2,
156
+ :name => 'Budget Name',
157
+ )
158
+
159
+ HTTParty.should_receive(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
160
+
161
+ budget.update(@api).should be_false
162
+ end
163
+
164
+ it "Delete budget (success)" do
165
+ budget = Osm::Budget.new(
166
+ :id => 1,
167
+ :section_id => 2,
168
+ :name => 'Budget Name',
169
+ )
170
+
171
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=deleteCategory&sectionid=2"
172
+ HTTParty.should_receive(:post).with(url, :body => {
173
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
174
+ 'token' => @CONFIGURATION[:api][:osm][:token],
175
+ 'userid' => 'user_id',
176
+ 'secret' => 'secret',
177
+ 'categoryid' => 1,
178
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
179
+
180
+ budget.delete(@api).should be_true
181
+ end
182
+
183
+ it "Delete budget (failure)" do
184
+ budget = Osm::Budget.new(
185
+ :id => 1,
186
+ :section_id => 2,
187
+ :name => 'Budget Name',
188
+ )
189
+
190
+ url = "https://www.onlinescoutmanager.co.uk/finances.php?action=deleteCategory&sectionid=2"
191
+ HTTParty.should_receive(:post).with(url, :body => {
192
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
193
+ 'token' => @CONFIGURATION[:api][:osm][:token],
194
+ 'userid' => 'user_id',
195
+ 'secret' => 'secret',
196
+ 'categoryid' => 1,
197
+ }) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
198
+
199
+ budget.delete(@api).should be_false
200
+ end
201
+
202
+ end
203
+
204
+
205
+ end