moip-assinaturas 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -52,7 +52,11 @@ plan = {
52
52
  length: 1,
53
53
  unit: "MONTH"
54
54
  },
55
- billing_cycles: 12
55
+ billing_cycles: 12,
56
+ trial: {
57
+ enabled: true,
58
+ days: 10
59
+ }
56
60
  }
57
61
 
58
62
  request = Moip::Assinaturas::Plan.create(plan)
@@ -1,5 +1,5 @@
1
1
  module Moip
2
2
  module Assinaturas
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -31,16 +31,19 @@ module Moip::Assinaturas
31
31
  end
32
32
  end
33
33
 
34
- def on(model, event, &block)
34
+ def on(model, on_events, &block)
35
+
35
36
  unless events[model]
36
37
  events[model] = {}
37
38
  end
38
39
 
39
- unless events[model][event]
40
- events[model][event] = []
41
- end
40
+ (on_events.is_a?(Array) ? on_events : [on_events]).each do |event|
41
+ unless events[model][event]
42
+ events[model][event] = []
43
+ end
42
44
 
43
- events[model][event] << block
45
+ events[model][event] << block
46
+ end
44
47
  end
45
48
 
46
49
  def run
@@ -8,5 +8,9 @@
8
8
  "interval": {
9
9
  "length": 1,
10
10
  "unit": "MONTH"
11
- }
11
+ },
12
+ "trial": {
13
+ "enabled": true,
14
+ "days": 10
15
+ }
12
16
  }
@@ -10,5 +10,9 @@
10
10
  "length": 1,
11
11
  "unit": "MONTH"
12
12
  },
13
- "billing_cycles": 1
13
+ "billing_cycles": 1,
14
+ "trial": {
15
+ "enabled": true,
16
+ "days": 10
17
+ }
14
18
  }
@@ -28,5 +28,17 @@
28
28
  "code": "cliente1",
29
29
  "fullname": "Nome e Sobrenome",
30
30
  "email": "assinaturas@moip.com.br"
31
+ },
32
+ "trial": {
33
+ "start": {
34
+ "month": 9,
35
+ "year": 2013,
36
+ "day": 27
37
+ },
38
+ "end": {
39
+ "month": 10,
40
+ "year": 2013,
41
+ "day": 17
42
+ }
31
43
  }
32
44
  }
@@ -15,7 +15,11 @@ describe Moip::Assinaturas::Plan do
15
15
  length: 1,
16
16
  unit: "MONTH"
17
17
  },
18
- billing_cycles: 12
18
+ billing_cycles: 12,
19
+ trial: {
20
+ enabled: true,
21
+ days: 10
22
+ }
19
23
  }
20
24
 
21
25
  FakeWeb.register_uri(
@@ -58,4 +62,12 @@ describe Moip::Assinaturas::Plan do
58
62
  request[:plan][:code].should == 'plano01'
59
63
  end
60
64
 
65
+ context "Trial" do
66
+ it "should get details from a plan with trial" do
67
+ request = Moip::Assinaturas::Plan.details('plano01')
68
+ expect(request[:plan][:trial][:days]).to eq 10
69
+ expect(request[:plan][:trial][:enabled]).to be_true
70
+ end
71
+ end
72
+
61
73
  end
@@ -1,6 +1,13 @@
1
1
  # coding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
+ RSpec::Matchers.define :have_valid_trial_dates do
5
+ match do |actual|
6
+ (actual[:start][:day] == 27 && actual[:start][:month] == 9 && actual[:start][:year] == 2013) &&
7
+ (actual[:end][:day] == 17 && actual[:end][:month] == 10 && actual[:end][:year] == 2013)
8
+ end
9
+ end
10
+
4
11
  describe Moip::Assinaturas::Subscription do
5
12
 
6
13
  before(:all) do
@@ -79,5 +86,11 @@ describe Moip::Assinaturas::Subscription do
79
86
  request[:success].should be_true
80
87
  end
81
88
 
89
+ context "Trial" do
90
+ it "should get the subscription details with trial" do
91
+ request = Moip::Assinaturas::Subscription.details('assinatura1')
92
+ expect(request[:subscription][:trial]).to have_valid_trial_dates
93
+ end
94
+ end
82
95
 
83
96
  end
@@ -52,16 +52,23 @@ describe Moip::Assinaturas::Webhooks do
52
52
  its(:resource) { should eq({ 'test' => 'test generic resource' }) }
53
53
  end
54
54
 
55
- describe '#on(model, event, &block)' do
55
+ describe '#on(model, on_events, &block)' do
56
56
  let!(:model) { 'model' }
57
- let!(:event) { 'event' }
57
+ let!(:event_1) { 'event_1' }
58
+ let!(:event_2) { 'event_2' }
58
59
  let!(:block) { lambda { } }
59
60
 
60
61
  subject(:hook) { Moip::Assinaturas::Webhooks.build(params) }
61
62
 
62
63
  it "should adding this block to events" do
63
- hook.on(model, event, &block)
64
- hook.events[model][event].should eq([block])
64
+ hook.on(model, event_1, &block)
65
+ hook.events[model][event_1].should eq([block])
66
+ end
67
+
68
+ it "should receive an array of events and add this block to events" do
69
+ hook.on(model, [event_1, event_2], &block)
70
+ hook.events[model][event_1].should eq([block])
71
+ hook.events[model][event_2].should eq([block])
65
72
  end
66
73
  end
67
74
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moip-assinaturas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec