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 +5 -1
- data/lib/moip-assinaturas/version.rb +1 -1
- data/lib/moip-assinaturas/webhooks.rb +8 -5
- data/spec/fixtures/create_plan.json +5 -1
- data/spec/fixtures/details_plan.json +5 -1
- data/spec/fixtures/details_subscription.json +12 -0
- data/spec/moip-assinaturas/plan_spec.rb +13 -1
- data/spec/moip-assinaturas/subscription_spec.rb +13 -0
- data/spec/moip-assinaturas/webhooks_spec.rb +11 -4
- metadata +2 -2
data/README.md
CHANGED
@@ -31,16 +31,19 @@ module Moip::Assinaturas
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def on(model,
|
34
|
+
def on(model, on_events, &block)
|
35
|
+
|
35
36
|
unless events[model]
|
36
37
|
events[model] = {}
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
-
events[model][event]
|
41
|
-
|
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
|
-
|
45
|
+
events[model][event] << block
|
46
|
+
end
|
44
47
|
end
|
45
48
|
|
46
49
|
def run
|
@@ -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,
|
55
|
+
describe '#on(model, on_events, &block)' do
|
56
56
|
let!(:model) { 'model' }
|
57
|
-
let!(:
|
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,
|
64
|
-
hook.events[model][
|
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.
|
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-
|
12
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|