gocardless 1.11.2 → 1.12.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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/gocardless.gemspec +5 -5
- data/lib/gocardless.rb +11 -2
- data/lib/gocardless/client.rb +1 -0
- data/lib/gocardless/version.rb +1 -1
- data/spec/bill_spec.rb +7 -7
- data/spec/client_spec.rb +109 -104
- data/spec/gocardless_spec.rb +20 -2
- data/spec/page_spec.rb +11 -11
- data/spec/paginator_spec.rb +16 -16
- data/spec/pre_authorization_spec.rb +1 -1
- data/spec/resource_spec.rb +61 -61
- data/spec/spec_helper.rb +4 -4
- data/spec/subscription_spec.rb +1 -1
- data/spec/user_spec.rb +4 -4
- data/spec/utils_spec.rb +62 -58
- metadata +14 -13
data/spec/gocardless_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe GoCardless do
|
|
10
10
|
|
11
11
|
describe ".account_details=" do
|
12
12
|
it "creates a Client instance" do
|
13
|
-
GoCardless::Client.
|
13
|
+
expect(GoCardless::Client).to receive :new
|
14
14
|
subject.account_details = @details
|
15
15
|
end
|
16
16
|
|
@@ -21,12 +21,30 @@ describe GoCardless do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe ".environment=" do
|
25
|
+
subject(:method) { -> { GoCardless.environment = gc_env } }
|
26
|
+
|
27
|
+
context "with a valid environment" do
|
28
|
+
let(:gc_env) { :production }
|
29
|
+
it { is_expected.to_not raise_error }
|
30
|
+
it 'sets the environment' do
|
31
|
+
method.call
|
32
|
+
expect(GoCardless.environment).to eq(gc_env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with an invalid environment" do
|
37
|
+
let(:gc_env) { :foobar }
|
38
|
+
it { is_expected.to raise_error }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
24
42
|
|
25
43
|
describe "delegated methods" do
|
26
44
|
%w(new_subscription_url new_pre_authorization_url new_bill_url confirm_resource webhook_valid?).each do |name|
|
27
45
|
it "#{name} delegates to @client" do
|
28
46
|
subject.account_details = @details
|
29
|
-
subject.instance_variable_get(:@client).
|
47
|
+
expect(subject.instance_variable_get(:@client)).to receive(name.to_sym)
|
30
48
|
subject.send(name)
|
31
49
|
end
|
32
50
|
|
data/spec/page_spec.rb
CHANGED
@@ -14,12 +14,12 @@ describe GoCardless::Page do
|
|
14
14
|
|
15
15
|
context "when there is next page available" do
|
16
16
|
let(:links) {{ "next" => 2, "last" => 2 }}
|
17
|
-
it {
|
17
|
+
it { is_expected.to be_truthy }
|
18
18
|
end
|
19
19
|
|
20
20
|
context "when there is no next page" do
|
21
21
|
let(:links) {{ "previous" => 1, "first" => 1 }}
|
22
|
-
it {
|
22
|
+
it { is_expected.to be_falsey }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -28,12 +28,12 @@ describe GoCardless::Page do
|
|
28
28
|
|
29
29
|
context "when there is next page available" do
|
30
30
|
let(:links) {{ "next" => 2, "last" => 2 }}
|
31
|
-
it {
|
31
|
+
it { is_expected.to eq(2) }
|
32
32
|
end
|
33
33
|
|
34
34
|
context "when there is no next page" do
|
35
35
|
let(:links) {{ "previous" => 1, "first" => 1 }}
|
36
|
-
it {
|
36
|
+
it { is_expected.to be_nil }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,12 +42,12 @@ describe GoCardless::Page do
|
|
42
42
|
|
43
43
|
context "when there is previous page available" do
|
44
44
|
let(:links) {{ "previous" => 1, "first" => 1 }}
|
45
|
-
it {
|
45
|
+
it { is_expected.to eq(1) }
|
46
46
|
end
|
47
47
|
|
48
48
|
context "when there is no previous page" do
|
49
49
|
let(:links) {{ "next" => 2, "last" => 2 }}
|
50
|
-
it {
|
50
|
+
it { is_expected.to be_nil }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -56,12 +56,12 @@ describe GoCardless::Page do
|
|
56
56
|
|
57
57
|
context "when there is first page available" do
|
58
58
|
let(:links) {{ "first" => 1, "previous" => 1 }}
|
59
|
-
it {
|
59
|
+
it { is_expected.to eq(1) }
|
60
60
|
end
|
61
61
|
|
62
62
|
context "when there is no first page" do
|
63
63
|
let(:links) {{ "next" => 2, "last" => 2 }}
|
64
|
-
it {
|
64
|
+
it { is_expected.to be_nil }
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -70,12 +70,12 @@ describe GoCardless::Page do
|
|
70
70
|
|
71
71
|
context "when there is last page available" do
|
72
72
|
let(:links) {{ "next" => 2, "last" => 2 }}
|
73
|
-
it {
|
73
|
+
it { is_expected.to eq(2) }
|
74
74
|
end
|
75
75
|
|
76
76
|
context "when there is no last page" do
|
77
77
|
let(:links) {{ "previous" => 1, "first" => 1 }}
|
78
|
-
it {
|
78
|
+
it { is_expected.to be_nil }
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -86,7 +86,7 @@ describe GoCardless::Page do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "properly initialises the resources" do
|
89
|
-
page.map(&:id).
|
89
|
+
expect(page.map(&:id)).to eq(['a', 'b'])
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
data/spec/paginator_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe GoCardless::Paginator do
|
|
19
19
|
let(:response_p2) { double(:headers => headers_p2, :parsed => [{:id => 'b'}]) }
|
20
20
|
|
21
21
|
let(:client) { double('client') }
|
22
|
-
before { client.
|
22
|
+
before { allow(client).to receive(:api_request).and_return(response_p1, response_p2,
|
23
23
|
response_p1, response_p2) }
|
24
24
|
|
25
25
|
let(:paginator) { described_class.new(client, resource_class, path, query) }
|
@@ -28,17 +28,17 @@ describe GoCardless::Paginator do
|
|
28
28
|
describe "#per_page" do
|
29
29
|
context "given no arguments" do
|
30
30
|
subject { paginator.per_page }
|
31
|
-
it {
|
31
|
+
it { is_expected.to eq(per_page) }
|
32
32
|
end
|
33
33
|
|
34
34
|
context "given an argument" do
|
35
35
|
it "is chainable" do
|
36
|
-
paginator.per_page(60).
|
36
|
+
expect(paginator.per_page(60)).to eq(paginator)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
it "resets pagination metadata" do
|
41
|
-
paginator.
|
41
|
+
expect(paginator).to receive(:load_page).exactly(2).times
|
42
42
|
paginator.count # reset metadata, check that we have to reload it
|
43
43
|
paginator.per_page(50)
|
44
44
|
paginator.count
|
@@ -47,7 +47,7 @@ describe GoCardless::Paginator do
|
|
47
47
|
|
48
48
|
describe "#load_page" do
|
49
49
|
it "asks the client for the correct path" do
|
50
|
-
client.
|
50
|
+
expect(client).to receive(:api_request).
|
51
51
|
with(:get, '/test', anything).
|
52
52
|
and_return(response_p1)
|
53
53
|
paginator.page(page_number)
|
@@ -55,9 +55,9 @@ describe GoCardless::Paginator do
|
|
55
55
|
|
56
56
|
it "passes the correct pagination parameters through" do
|
57
57
|
pagination_params = { :page => page_number, :per_page => per_page }
|
58
|
-
client.
|
59
|
-
opts[:params].
|
60
|
-
|
58
|
+
expect(client).to receive(:api_request) { |_, _, opts|
|
59
|
+
expect(opts[:params]).to include pagination_params
|
60
|
+
}.and_return(response_p1)
|
61
61
|
paginator.page(page_number)
|
62
62
|
end
|
63
63
|
end
|
@@ -89,19 +89,19 @@ describe GoCardless::Paginator do
|
|
89
89
|
context "when metadata is loaded" do
|
90
90
|
before { paginator.page(1) }
|
91
91
|
|
92
|
-
it {
|
92
|
+
it { is_expected.to eq(15) }
|
93
93
|
|
94
94
|
it "doesn't reload metadata" do
|
95
|
-
paginator.
|
95
|
+
expect(paginator).not_to receive(:load_page)
|
96
96
|
paginator.count
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
context "when metadata is not loaded" do
|
101
|
-
it {
|
101
|
+
it { is_expected.to eq(15) }
|
102
102
|
|
103
103
|
it "loads metadata" do
|
104
|
-
paginator.
|
104
|
+
expect(paginator).to receive(:load_page)
|
105
105
|
paginator.count
|
106
106
|
end
|
107
107
|
end
|
@@ -113,19 +113,19 @@ describe GoCardless::Paginator do
|
|
113
113
|
context "when metadata is loaded" do
|
114
114
|
before { paginator.page(1) }
|
115
115
|
|
116
|
-
it {
|
116
|
+
it { is_expected.to eq(2) }
|
117
117
|
|
118
118
|
it "doesn't reload metadata" do
|
119
|
-
paginator.
|
119
|
+
expect(paginator).not_to receive(:load_page)
|
120
120
|
paginator.page_count
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
context "when metadata is not loaded" do
|
125
|
-
it {
|
125
|
+
it { is_expected.to eq(2) }
|
126
126
|
|
127
127
|
it "loads metadata" do
|
128
|
-
paginator.
|
128
|
+
expect(paginator).to receive(:load_page)
|
129
129
|
paginator.page_count
|
130
130
|
end
|
131
131
|
end
|
@@ -9,7 +9,7 @@ describe GoCardless::PreAuthorization do
|
|
9
9
|
let(:preauth) { GoCardless::PreAuthorization.new(:id => '009988') }
|
10
10
|
|
11
11
|
it "should be cancellable" do
|
12
|
-
client.
|
12
|
+
expect(client).to receive(:api_put).with('/pre_authorizations/009988/cancel')
|
13
13
|
preauth.cancel!
|
14
14
|
end
|
15
15
|
|
data/spec/resource_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GoCardless::Resource do
|
|
7
7
|
end
|
8
8
|
props = {:id => 1, :name => 'test', :uri => 'http://test'}
|
9
9
|
resource = test_resource.new(props)
|
10
|
-
props.each { |k,v| resource.send(k).
|
10
|
+
props.each { |k,v| expect(resource.send(k)).to eq(v) }
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#date_writer" do
|
@@ -16,16 +16,16 @@ describe GoCardless::Resource do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "creates date writers" do
|
19
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
20
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
19
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :created_at= }
|
20
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :modified_at= }
|
21
21
|
end
|
22
22
|
|
23
23
|
it "date writers work properly" do
|
24
24
|
time = '2011-12-12T12:00:00Z'
|
25
25
|
resource = test_resource.new(:created_at => time)
|
26
26
|
date_time = resource.instance_variable_get(:@created_at)
|
27
|
-
date_time.
|
28
|
-
date_time.strftime('%Y-%m-%dT%H:%M:%SZ').
|
27
|
+
expect(date_time).to be_instance_of DateTime
|
28
|
+
expect(date_time.strftime('%Y-%m-%dT%H:%M:%SZ')).to eq(time)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -35,17 +35,17 @@ describe GoCardless::Resource do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "creates date readers and writers" do
|
38
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
39
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
40
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
41
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
38
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :created_at= }
|
39
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :created_at }
|
40
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :modified_at= }
|
41
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :modified_at }
|
42
42
|
end
|
43
43
|
|
44
44
|
it "date readers work properly" do
|
45
45
|
resource = test_resource.new
|
46
46
|
date = DateTime.now
|
47
47
|
resource.instance_variable_set(:@created_at, date)
|
48
|
-
resource.created_at.
|
48
|
+
expect(resource.created_at).to eq(date)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -56,10 +56,10 @@ describe GoCardless::Resource do
|
|
56
56
|
|
57
57
|
it "instantiates the correct object" do
|
58
58
|
mock_client = double
|
59
|
-
mock_client.
|
59
|
+
expect(mock_client).to receive(:api_get).and_return({:id => 123})
|
60
60
|
resource = test_resource.find_with_client(mock_client, 123)
|
61
|
-
resource.
|
62
|
-
resource.id.
|
61
|
+
expect(resource).to be_a test_resource
|
62
|
+
expect(resource.id).to eq(123)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -69,8 +69,8 @@ describe GoCardless::Resource do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "calls find with the default client" do
|
72
|
-
GoCardless.
|
73
|
-
test_resource.
|
72
|
+
allow(GoCardless).to receive_messages(:client => double)
|
73
|
+
expect(test_resource).to receive(:find_with_client).with(GoCardless.client, 1)
|
74
74
|
test_resource.find(1)
|
75
75
|
unset_ivar GoCardless, :client
|
76
76
|
end
|
@@ -86,16 +86,16 @@ describe GoCardless::Resource do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
describe "creates reference writers" do
|
89
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
90
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
91
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
92
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
89
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant= }
|
90
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant_id= }
|
91
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user= }
|
92
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user_id= }
|
93
93
|
end
|
94
94
|
|
95
95
|
it "direct assignment methods work properly" do
|
96
96
|
resource = test_resource.new
|
97
97
|
resource.user = GoCardless::User.new(:id => 123)
|
98
|
-
resource.instance_variable_get(:@user_id).
|
98
|
+
expect(resource.instance_variable_get(:@user_id)).to eq(123)
|
99
99
|
end
|
100
100
|
|
101
101
|
it "requires args to end with _id" do
|
@@ -124,10 +124,10 @@ describe GoCardless::Resource do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
describe "creates reference readers" do
|
127
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
128
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
129
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
130
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
127
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant }
|
128
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant_id }
|
129
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user }
|
130
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user_id }
|
131
131
|
end
|
132
132
|
|
133
133
|
it "lookup methods work properly" do
|
@@ -137,8 +137,8 @@ describe GoCardless::Resource do
|
|
137
137
|
@client.merchant_id = '123'
|
138
138
|
stub_get(@client, {:id => 123})
|
139
139
|
user = resource.user
|
140
|
-
user.
|
141
|
-
user.id.
|
140
|
+
expect(user).to be_a GoCardless::User
|
141
|
+
expect(user.id).to eq(123)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "requires args to end with _id" do
|
@@ -158,20 +158,20 @@ describe GoCardless::Resource do
|
|
158
158
|
end
|
159
159
|
|
160
160
|
describe "creates reference readers and writers" do
|
161
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
162
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
163
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
164
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
165
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
166
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
167
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
168
|
-
specify { test_resource.instance_methods.map(&:to_sym).
|
161
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant }
|
162
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant_id }
|
163
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user }
|
164
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user_id }
|
165
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant= }
|
166
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :merchant_id= }
|
167
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user= }
|
168
|
+
specify { expect(test_resource.instance_methods.map(&:to_sym)).to include :user_id= }
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
172
|
it "#persisted? works" do
|
173
|
-
GoCardless::Resource.new.persisted
|
174
|
-
GoCardless::Resource.new(:id => 1).persisted
|
173
|
+
expect(GoCardless::Resource.new.persisted?).to be_falsey
|
174
|
+
expect(GoCardless::Resource.new(:id => 1).persisted?).to be_truthy
|
175
175
|
end
|
176
176
|
|
177
177
|
describe "#save" do
|
@@ -193,28 +193,28 @@ describe GoCardless::Resource do
|
|
193
193
|
client = double
|
194
194
|
data = {:x => 1, :y => 2}
|
195
195
|
resource = @test_resource.new_with_client(client, data)
|
196
|
-
client.
|
196
|
+
expect(client).to receive(:api_post).with(anything, data)
|
197
197
|
resource.save
|
198
198
|
end
|
199
199
|
|
200
200
|
it "sends the correct path" do
|
201
201
|
client = double
|
202
202
|
resource = @test_resource.new_with_client(client)
|
203
|
-
client.
|
203
|
+
expect(client).to receive(:api_post).with('/test', anything)
|
204
204
|
resource.save
|
205
205
|
end
|
206
206
|
|
207
207
|
it "POSTs when not persisted" do
|
208
208
|
client = double
|
209
209
|
resource = @test_resource.new_with_client(client)
|
210
|
-
client.
|
210
|
+
expect(client).to receive(:api_post)
|
211
211
|
resource.save
|
212
212
|
end
|
213
213
|
|
214
214
|
it "PUTs when already persisted" do
|
215
215
|
client = double
|
216
216
|
resource = @test_resource.new_with_client(client, :id => 1)
|
217
|
-
client.
|
217
|
+
expect(client).to receive(:api_put)
|
218
218
|
resource.save
|
219
219
|
end
|
220
220
|
end
|
@@ -263,7 +263,7 @@ describe GoCardless::Resource do
|
|
263
263
|
|
264
264
|
attrs = {:id => 1, :uri => 'http:', :x => 'y'}
|
265
265
|
resource = test_resource.new_with_client(double, attrs)
|
266
|
-
resource.to_hash.
|
266
|
+
expect(resource.to_hash).to eq(attrs)
|
267
267
|
end
|
268
268
|
|
269
269
|
it "#to_json converts to the correct JSON format" do
|
@@ -281,15 +281,15 @@ describe GoCardless::Resource do
|
|
281
281
|
})
|
282
282
|
|
283
283
|
result = MultiJson.decode(bill.to_json)
|
284
|
-
result['amount'].
|
285
|
-
result['when'].
|
286
|
-
result['person_id'].
|
284
|
+
expect(result['amount']).to eq(bill.amount)
|
285
|
+
expect(result['when']).to eq(time_str)
|
286
|
+
expect(result['person_id']).to eq(15)
|
287
287
|
end
|
288
288
|
|
289
289
|
describe "resource permissions" do
|
290
290
|
it "are not given by default" do
|
291
|
-
GoCardless::Resource.creatable
|
292
|
-
GoCardless::Resource.updatable
|
291
|
+
expect(GoCardless::Resource.creatable?).to be_falsey
|
292
|
+
expect(GoCardless::Resource.updatable?).to be_falsey
|
293
293
|
end
|
294
294
|
|
295
295
|
it "are present when specified" do
|
@@ -301,14 +301,14 @@ describe GoCardless::Resource do
|
|
301
301
|
updatable
|
302
302
|
end
|
303
303
|
|
304
|
-
CreatableResource.creatable
|
305
|
-
CreatableResource.updatable
|
304
|
+
expect(CreatableResource.creatable?).to be_truthy
|
305
|
+
expect(CreatableResource.updatable?).to be_falsey
|
306
306
|
|
307
|
-
UpdatableResource.creatable
|
308
|
-
UpdatableResource.updatable
|
307
|
+
expect(UpdatableResource.creatable?).to be_falsey
|
308
|
+
expect(UpdatableResource.updatable?).to be_truthy
|
309
309
|
|
310
|
-
GoCardless::Resource.creatable
|
311
|
-
GoCardless::Resource.updatable
|
310
|
+
expect(GoCardless::Resource.creatable?).to be_falsey
|
311
|
+
expect(GoCardless::Resource.updatable?).to be_falsey
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
@@ -324,31 +324,31 @@ describe GoCardless::Resource do
|
|
324
324
|
|
325
325
|
it "are defined on instances" do
|
326
326
|
r = test_resource.new(@attrs)
|
327
|
-
r.
|
327
|
+
expect(r).to respond_to :bills
|
328
328
|
end
|
329
329
|
|
330
330
|
it "aren't defined for other instances of the class" do
|
331
331
|
test_resource.new(@attrs)
|
332
332
|
resource = test_resource.new
|
333
|
-
resource.
|
333
|
+
expect(resource).not_to respond_to :bills
|
334
334
|
end
|
335
335
|
|
336
336
|
it "use the correct resource" do
|
337
|
-
GoCardless::Paginator.
|
337
|
+
expect(GoCardless::Paginator).to receive(:new).
|
338
338
|
with(anything, GoCardless::Bill, anything, anything)
|
339
339
|
r = test_resource.new_with_client(double, @attrs)
|
340
340
|
r.bills
|
341
341
|
end
|
342
342
|
|
343
343
|
it "use the correct uri path" do
|
344
|
-
GoCardless::Paginator.
|
344
|
+
expect(GoCardless::Paginator).to receive(:new).
|
345
345
|
with(anything, anything, '/api/bills/', anything)
|
346
346
|
r = test_resource.new_with_client(double, @attrs)
|
347
347
|
r.bills
|
348
348
|
end
|
349
349
|
|
350
350
|
it "strips the api prefix from the path" do
|
351
|
-
GoCardless::Paginator.
|
351
|
+
expect(GoCardless::Paginator).to receive(:new).
|
352
352
|
with(anything, anything, '/bills/', anything)
|
353
353
|
uris = {'bills' => 'https://test.com/api/v123/bills/'}
|
354
354
|
r = test_resource.new_with_client(double, 'sub_resource_uris' => uris)
|
@@ -357,7 +357,7 @@ describe GoCardless::Resource do
|
|
357
357
|
|
358
358
|
it "use the correct query string params" do
|
359
359
|
query = { 'merchant_id' => '1' }
|
360
|
-
GoCardless::Paginator.
|
360
|
+
expect(GoCardless::Paginator).to receive(:new).
|
361
361
|
with(anything, anything, anything, query)
|
362
362
|
r = test_resource.new_with_client(double, @attrs)
|
363
363
|
r.bills
|
@@ -365,7 +365,7 @@ describe GoCardless::Resource do
|
|
365
365
|
|
366
366
|
it "adds provided params to existing query string params" do
|
367
367
|
params = { 'merchant_id' => '1', :amount => '10.00' }
|
368
|
-
GoCardless::Paginator.
|
368
|
+
expect(GoCardless::Paginator).to receive(:new).
|
369
369
|
with(anything, anything, anything, params)
|
370
370
|
r = test_resource.new_with_client(double, @attrs)
|
371
371
|
r.bills(:amount => '10.00')
|
@@ -373,7 +373,7 @@ describe GoCardless::Resource do
|
|
373
373
|
|
374
374
|
it "adds provided params when there are no existing query string params" do
|
375
375
|
params = { :source_id => 'xxx' }
|
376
|
-
GoCardless::Paginator.
|
376
|
+
expect(GoCardless::Paginator).to receive(:new).
|
377
377
|
with(anything, anything, anything, params)
|
378
378
|
r = test_resource.new_with_client(double, {
|
379
379
|
'sub_resource_uris' => {
|
@@ -385,7 +385,7 @@ describe GoCardless::Resource do
|
|
385
385
|
|
386
386
|
it "return instances of the correct resource class" do
|
387
387
|
r = test_resource.new_with_client(double, @attrs)
|
388
|
-
r.bills.
|
388
|
+
expect(r.bills).to be_a GoCardless::Paginator
|
389
389
|
end
|
390
390
|
end
|
391
391
|
end
|