cardiac 0.2.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/LICENSE +22 -0
- data/Rakefile +66 -0
- data/cardiac-0.2.0.pre2.gem +0 -0
- data/cardiac.gemspec +48 -0
- data/lib/cardiac/declarations.rb +70 -0
- data/lib/cardiac/errors.rb +65 -0
- data/lib/cardiac/log_subscriber.rb +55 -0
- data/lib/cardiac/model/attributes.rb +146 -0
- data/lib/cardiac/model/base.rb +161 -0
- data/lib/cardiac/model/callbacks.rb +47 -0
- data/lib/cardiac/model/declarations.rb +106 -0
- data/lib/cardiac/model/dirty.rb +117 -0
- data/lib/cardiac/model/locale/en.yml +7 -0
- data/lib/cardiac/model/operations.rb +49 -0
- data/lib/cardiac/model/persistence.rb +171 -0
- data/lib/cardiac/model/querying.rb +129 -0
- data/lib/cardiac/model/validations.rb +124 -0
- data/lib/cardiac/model.rb +17 -0
- data/lib/cardiac/operation_builder.rb +75 -0
- data/lib/cardiac/operation_handler.rb +215 -0
- data/lib/cardiac/railtie.rb +20 -0
- data/lib/cardiac/reflections.rb +85 -0
- data/lib/cardiac/representation.rb +124 -0
- data/lib/cardiac/resource/adapter.rb +178 -0
- data/lib/cardiac/resource/builder.rb +107 -0
- data/lib/cardiac/resource/codec_methods.rb +58 -0
- data/lib/cardiac/resource/config_methods.rb +39 -0
- data/lib/cardiac/resource/extension_methods.rb +115 -0
- data/lib/cardiac/resource/request_methods.rb +138 -0
- data/lib/cardiac/resource/subresource.rb +88 -0
- data/lib/cardiac/resource/uri_methods.rb +176 -0
- data/lib/cardiac/resource.rb +77 -0
- data/lib/cardiac/util.rb +120 -0
- data/lib/cardiac/version.rb +3 -0
- data/lib/cardiac.rb +61 -0
- data/spec/rails-3.2/Gemfile +9 -0
- data/spec/rails-3.2/Gemfile.lock +136 -0
- data/spec/rails-3.2/Rakefile +10 -0
- data/spec/rails-3.2/app_root/app/assets/javascripts/application.js +15 -0
- data/spec/rails-3.2/app_root/app/assets/stylesheets/application.css +13 -0
- data/spec/rails-3.2/app_root/app/controllers/application_controller.rb +3 -0
- data/spec/rails-3.2/app_root/app/helpers/application_helper.rb +2 -0
- data/spec/rails-3.2/app_root/app/views/layouts/application.html.erb +14 -0
- data/spec/rails-3.2/app_root/config/application.rb +29 -0
- data/spec/rails-3.2/app_root/config/boot.rb +13 -0
- data/spec/rails-3.2/app_root/config/database.yml +25 -0
- data/spec/rails-3.2/app_root/config/environment.rb +5 -0
- data/spec/rails-3.2/app_root/config/environments/development.rb +10 -0
- data/spec/rails-3.2/app_root/config/environments/production.rb +11 -0
- data/spec/rails-3.2/app_root/config/environments/test.rb +11 -0
- data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails-3.2/app_root/config/initializers/inflections.rb +15 -0
- data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +5 -0
- data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +7 -0
- data/spec/rails-3.2/app_root/config/initializers/session_store.rb +8 -0
- data/spec/rails-3.2/app_root/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails-3.2/app_root/config/locales/en.yml +5 -0
- data/spec/rails-3.2/app_root/config/routes.rb +2 -0
- data/spec/rails-3.2/app_root/db/test.sqlite3 +0 -0
- data/spec/rails-3.2/app_root/log/test.log +2403 -0
- data/spec/rails-3.2/app_root/public/404.html +26 -0
- data/spec/rails-3.2/app_root/public/422.html +26 -0
- data/spec/rails-3.2/app_root/public/500.html +25 -0
- data/spec/rails-3.2/app_root/public/favicon.ico +0 -0
- data/spec/rails-3.2/app_root/script/rails +6 -0
- data/spec/rails-3.2/spec/spec_helper.rb +25 -0
- data/spec/rails-4.0/Gemfile +9 -0
- data/spec/rails-4.0/Gemfile.lock +132 -0
- data/spec/rails-4.0/Rakefile +10 -0
- data/spec/rails-4.0/app_root/app/assets/javascripts/application.js +15 -0
- data/spec/rails-4.0/app_root/app/assets/stylesheets/application.css +13 -0
- data/spec/rails-4.0/app_root/app/controllers/application_controller.rb +3 -0
- data/spec/rails-4.0/app_root/app/helpers/application_helper.rb +2 -0
- data/spec/rails-4.0/app_root/app/views/layouts/application.html.erb +14 -0
- data/spec/rails-4.0/app_root/config/application.rb +28 -0
- data/spec/rails-4.0/app_root/config/boot.rb +13 -0
- data/spec/rails-4.0/app_root/config/database.yml +25 -0
- data/spec/rails-4.0/app_root/config/environment.rb +5 -0
- data/spec/rails-4.0/app_root/config/environments/development.rb +9 -0
- data/spec/rails-4.0/app_root/config/environments/production.rb +11 -0
- data/spec/rails-4.0/app_root/config/environments/test.rb +10 -0
- data/spec/rails-4.0/app_root/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails-4.0/app_root/config/initializers/inflections.rb +15 -0
- data/spec/rails-4.0/app_root/config/initializers/mime_types.rb +5 -0
- data/spec/rails-4.0/app_root/config/initializers/secret_token.rb +7 -0
- data/spec/rails-4.0/app_root/config/initializers/session_store.rb +8 -0
- data/spec/rails-4.0/app_root/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails-4.0/app_root/config/locales/en.yml +5 -0
- data/spec/rails-4.0/app_root/config/routes.rb +2 -0
- data/spec/rails-4.0/app_root/db/test.sqlite3 +0 -0
- data/spec/rails-4.0/app_root/log/development.log +50 -0
- data/spec/rails-4.0/app_root/log/test.log +2399 -0
- data/spec/rails-4.0/app_root/public/404.html +26 -0
- data/spec/rails-4.0/app_root/public/422.html +26 -0
- data/spec/rails-4.0/app_root/public/500.html +25 -0
- data/spec/rails-4.0/app_root/public/favicon.ico +0 -0
- data/spec/rails-4.0/app_root/script/rails +6 -0
- data/spec/rails-4.0/spec/spec_helper.rb +25 -0
- data/spec/shared/cardiac/declarations_spec.rb +103 -0
- data/spec/shared/cardiac/model/base_spec.rb +446 -0
- data/spec/shared/cardiac/operation_builder_spec.rb +96 -0
- data/spec/shared/cardiac/operation_handler_spec.rb +82 -0
- data/spec/shared/cardiac/representation/reflection_spec.rb +73 -0
- data/spec/shared/cardiac/resource/adapter_spec.rb +83 -0
- data/spec/shared/cardiac/resource/builder_spec.rb +52 -0
- data/spec/shared/cardiac/resource/codec_methods_spec.rb +63 -0
- data/spec/shared/cardiac/resource/config_methods_spec.rb +52 -0
- data/spec/shared/cardiac/resource/extension_methods_spec.rb +215 -0
- data/spec/shared/cardiac/resource/request_methods_spec.rb +186 -0
- data/spec/shared/cardiac/resource/uri_methods_spec.rb +212 -0
- data/spec/shared/support/client_execution.rb +28 -0
- data/spec/spec_helper.rb +24 -0
- metadata +463 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::OperationBuilder do
|
4
|
+
|
5
|
+
let(:base_url) { 'http://localhost/prefix/segment?q=foobar' }
|
6
|
+
let(:base_uri) { URI(base_url) }
|
7
|
+
let(:resource) { Cardiac::Resource.new(base_uri) }
|
8
|
+
let(:builder) { Cardiac::OperationBuilder.new(resource.dup) }
|
9
|
+
|
10
|
+
subject { builder }
|
11
|
+
|
12
|
+
shared_examples 'a URI builder' do |args,url|
|
13
|
+
calldesc = "##{args[0]}(#{args[1..-1].map(&:inspect).join(',')})"
|
14
|
+
|
15
|
+
subject { builder.send(*args) }
|
16
|
+
|
17
|
+
it "#{calldesc} should modify the new builder" do
|
18
|
+
expect(subject.to_resource.to_url).to eq(url)
|
19
|
+
unless url == base_url
|
20
|
+
expect(subject.to_resource.to_uri).not_to eq(base_uri)
|
21
|
+
expect(subject.to_resource.to_url).not_to eq(base_url)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#{calldesc} should not modify the original builder" do
|
26
|
+
unless url == base_url
|
27
|
+
expect(builder.to_resource.to_uri).to eq(base_uri)
|
28
|
+
expect(builder.to_resource.to_url).to eq(base_url)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
shared_examples 'a call builder' do |verb|
|
34
|
+
it { is_expected.to respond_to(verb) }
|
35
|
+
|
36
|
+
describe "##{verb}" do
|
37
|
+
subject { builder.send(verb, *args).to_resource }
|
38
|
+
let!(:args) { [] }
|
39
|
+
|
40
|
+
if verb==:call
|
41
|
+
describe '#method_value' do
|
42
|
+
subject { super().method_value }
|
43
|
+
it { is_expected.to be_nil }
|
44
|
+
end
|
45
|
+
else
|
46
|
+
describe '#method_value' do
|
47
|
+
subject { super().method_value }
|
48
|
+
it { is_expected.to eq(verb) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
shared_examples 'a call proxy' do |verb, mock|
|
55
|
+
it { is_expected.to respond_to(verb) }
|
56
|
+
|
57
|
+
include_context 'Client responses'
|
58
|
+
|
59
|
+
describe "##{verb}" do
|
60
|
+
include_context 'Client execution', verb, mock
|
61
|
+
|
62
|
+
subject { builder.send(verb, *args) }
|
63
|
+
let!(:args) { [] }
|
64
|
+
|
65
|
+
it 'should not raise an error' do
|
66
|
+
expect { subject.to_s }.not_to raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
shared_examples 'URI building' do
|
72
|
+
it_behaves_like 'a URI builder', [:scheme, 'https'], 'https://localhost/prefix/segment?q=foobar'
|
73
|
+
it_behaves_like 'a URI builder', [:https], 'https://localhost/prefix/segment?q=foobar'
|
74
|
+
it_behaves_like 'a URI builder', [:host, 'google.com'], 'http://google.com/prefix/segment?q=foobar'
|
75
|
+
it_behaves_like 'a URI builder', [:port, 8080], 'http://localhost:8080/prefix/segment?q=foobar'
|
76
|
+
it_behaves_like 'a URI builder', [:path, '1'], 'http://localhost/prefix/segment/1?q=foobar'
|
77
|
+
it_behaves_like 'a URI builder', [:query, 'q=barfoo'], 'http://localhost/prefix/segment?q=barfoo'
|
78
|
+
it_behaves_like 'a URI builder', [:query, {q: 1, r: 2}], 'http://localhost/prefix/segment?q=1&r=2'
|
79
|
+
end
|
80
|
+
|
81
|
+
include_examples 'URI building'
|
82
|
+
|
83
|
+
it_behaves_like 'a call builder', :get
|
84
|
+
it_behaves_like 'a call builder', :post
|
85
|
+
it_behaves_like 'a call builder', :put
|
86
|
+
it_behaves_like 'a call builder', :delete
|
87
|
+
|
88
|
+
describe Cardiac::OperationProxy do
|
89
|
+
let(:builder) { Cardiac::OperationProxy.new(resource.dup) }
|
90
|
+
|
91
|
+
include_examples 'URI building'
|
92
|
+
|
93
|
+
it_behaves_like 'a call proxy', :get, :success
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::OperationHandler do
|
4
|
+
|
5
|
+
let(:resource) { Cardiac::Resource.new('http://google.com') }
|
6
|
+
let(:client_options) { resource.send(:build_client_options) }
|
7
|
+
let(:client_handler) { }
|
8
|
+
|
9
|
+
subject do
|
10
|
+
described_class.new(client_options, nil, &client_handler)
|
11
|
+
end
|
12
|
+
|
13
|
+
include_context 'Client responses'
|
14
|
+
|
15
|
+
shared_examples 'successful responses' do |verb|
|
16
|
+
include_context 'Client execution', verb, :success
|
17
|
+
|
18
|
+
before :example do
|
19
|
+
resource.http_method(verb)
|
20
|
+
expect{ subject.transmit! }.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it { is_expected.to be_completed }
|
24
|
+
it { is_expected.to be_transmitted }
|
25
|
+
it { is_expected.not_to be_aborted }
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_examples 'unsuccessful responses' do |verb|
|
29
|
+
include_context 'Client execution', verb, :failure
|
30
|
+
|
31
|
+
before :example do
|
32
|
+
resource.http_method(verb)
|
33
|
+
expect{ subject.transmit! }.to raise_error(/Not Found/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it { is_expected.not_to be_completed }
|
37
|
+
it { is_expected.to be_transmitted }
|
38
|
+
it { is_expected.to be_aborted }
|
39
|
+
end
|
40
|
+
|
41
|
+
shared_examples 'aborted requests' do |verb|
|
42
|
+
before :example do
|
43
|
+
allow_any_instance_of(Cardiac::OperationHandler).to receive(:perform_request){|_| raise Errno::ECONNREFUSED }
|
44
|
+
resource.http_method(verb)
|
45
|
+
expect{ subject.transmit! }.to raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it { is_expected.not_to be_completed }
|
49
|
+
it { is_expected.not_to be_transmitted }
|
50
|
+
it { is_expected.to be_aborted }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'GET' do
|
54
|
+
it_behaves_like 'successful responses', :get
|
55
|
+
it_behaves_like 'unsuccessful responses', :get
|
56
|
+
it_behaves_like 'aborted requests', :get
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'POST' do
|
60
|
+
it_behaves_like 'successful responses', :post
|
61
|
+
it_behaves_like 'unsuccessful responses', :post
|
62
|
+
it_behaves_like 'aborted requests', :post
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'PUT' do
|
66
|
+
it_behaves_like 'successful responses', :put
|
67
|
+
it_behaves_like 'unsuccessful responses', :put
|
68
|
+
it_behaves_like 'aborted requests', :put
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'DELETE' do
|
72
|
+
it_behaves_like 'successful responses', :delete
|
73
|
+
it_behaves_like 'unsuccessful responses', :delete
|
74
|
+
it_behaves_like 'aborted requests', :delete
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'will not transmit without an HTTP verb' do
|
78
|
+
resource.http_method(nil)
|
79
|
+
expect { subject.transmit! }.to raise_error(Cardiac::InvalidOperationError)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::Representation::Reflection do
|
4
|
+
|
5
|
+
shared_context 'by extension' do |_extension,*rest|
|
6
|
+
let(:extension) { _extension }
|
7
|
+
subject { described_class.new(extension, *rest) }
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_examples 'default type' do |*rest|
|
11
|
+
describe '#extension' do
|
12
|
+
subject { super().extension }
|
13
|
+
it { is_expected.to eq(extension) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#default_type' do
|
17
|
+
subject { super().default_type }
|
18
|
+
it { is_expected.to be_present }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#types' do
|
22
|
+
it 'includes the default type' do
|
23
|
+
expect(subject.types).to be_include(subject.default_type)
|
24
|
+
end
|
25
|
+
it 'includes the application/:extension type' do
|
26
|
+
expect(subject.types).to be_include("application/#{extension}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
shared_examples 'default coder' do
|
32
|
+
describe '#coder' do
|
33
|
+
subject { super().coder }
|
34
|
+
it { is_expected.to eq(::Cardiac::Representation::Codecs.const_get(extension.to_s.classify)) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#coder' do
|
38
|
+
subject { super().coder }
|
39
|
+
it { is_expected.to be_respond_to(:decode) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#coder' do
|
43
|
+
subject { super().coder }
|
44
|
+
it { is_expected.to be_respond_to(:encode) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'JSON' do
|
49
|
+
include_context 'by extension', :json
|
50
|
+
include_examples 'default type'
|
51
|
+
include_examples 'default coder'
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'XML' do
|
55
|
+
include_context 'by extension', :xml
|
56
|
+
include_examples 'default type'
|
57
|
+
include_examples 'default coder'
|
58
|
+
|
59
|
+
describe '#types' do
|
60
|
+
subject { super().types }
|
61
|
+
it { is_expected.to be_include("text/xml") }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'unknown' do
|
66
|
+
include_context 'by extension', :unknown
|
67
|
+
|
68
|
+
it 'cannot be created' do
|
69
|
+
expect { subject }.to raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::ResourceAdapter do
|
4
|
+
|
5
|
+
let(:base_url) { 'http://localhost/prefix/segment?q=foobar' }
|
6
|
+
let(:base_uri) { URI(base_url) }
|
7
|
+
let(:resource) { Cardiac::Resource.new(base_uri) }
|
8
|
+
let(:adapter) { Cardiac::ResourceAdapter.new(nil, resource) }
|
9
|
+
|
10
|
+
include_context 'Client responses'
|
11
|
+
|
12
|
+
subject { adapter }
|
13
|
+
|
14
|
+
describe '#http_verb' do
|
15
|
+
subject { super().http_verb }
|
16
|
+
it { is_expected.to be_nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#payload' do
|
20
|
+
subject { super().payload }
|
21
|
+
it { is_expected.to be_nil }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#response' do
|
25
|
+
subject { super().response }
|
26
|
+
it { is_expected.to be_nil }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#result' do
|
30
|
+
subject { super().result }
|
31
|
+
it { is_expected.to be_nil }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#resource' do
|
35
|
+
subject { super().resource }
|
36
|
+
it { is_expected.to eq(resource) }
|
37
|
+
end
|
38
|
+
|
39
|
+
it { is_expected.to be_resolved }
|
40
|
+
|
41
|
+
describe '#call!()' do
|
42
|
+
|
43
|
+
describe 'successful responses' do
|
44
|
+
include_context 'Client execution', :get, :success
|
45
|
+
|
46
|
+
before :example do
|
47
|
+
resource.http_method(:get)
|
48
|
+
expect { @retval = adapter.call! }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#response' do
|
52
|
+
subject { adapter.response }
|
53
|
+
it { is_expected.to be_present }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#result' do
|
57
|
+
subject { adapter.result }
|
58
|
+
it { is_expected.to be_present }
|
59
|
+
end
|
60
|
+
|
61
|
+
it('returns true') { expect(@retval).to be_a(TrueClass) }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'failed responses' do
|
65
|
+
include_context 'Client execution', :get, :failure
|
66
|
+
|
67
|
+
before :example do
|
68
|
+
resource.http_method(:get)
|
69
|
+
expect { @retval = adapter.call! }.to raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#response' do
|
73
|
+
subject { adapter.response }
|
74
|
+
it { is_expected.not_to be_present }
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#result' do
|
78
|
+
subject { adapter.result }
|
79
|
+
it { is_expected.not_to be_present }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::ResourceBuilder do
|
4
|
+
|
5
|
+
let(:base_url) { 'http://localhost/prefix/segment?q=foobar' }
|
6
|
+
let(:base_uri) { URI(base_url) }
|
7
|
+
let(:resource) { Cardiac::Resource.new(base_uri) }
|
8
|
+
let(:builder) { Cardiac::ResourceBuilder.new(resource.dup) }
|
9
|
+
|
10
|
+
subject { builder }
|
11
|
+
|
12
|
+
shared_examples 'a non-operational resource' do |sym|
|
13
|
+
it { is_expected.not_to respond_to(sym) }
|
14
|
+
it("##{sym} should raise an error") { expect { builder.send(sym) }.to raise_error }
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples 'a URI builder' do |args,url|
|
18
|
+
calldesc = "##{args[0]}(#{args[1..-1].map(&:inspect).join(',')})"
|
19
|
+
|
20
|
+
subject { builder.send(*args) }
|
21
|
+
|
22
|
+
it "#{calldesc} should modify the new builder" do
|
23
|
+
expect(subject.to_resource.to_url).to eq(url)
|
24
|
+
unless url == base_url
|
25
|
+
expect(subject.to_resource.to_uri).not_to eq(base_uri)
|
26
|
+
expect(subject.to_resource.to_url).not_to eq(base_url)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#{calldesc} should not modify the original builder" do
|
31
|
+
unless url == base_url
|
32
|
+
expect(builder.to_resource.to_uri).to eq(base_uri)
|
33
|
+
expect(builder.to_resource.to_url).to eq(base_url)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it_behaves_like 'a URI builder', [:scheme, 'https'], 'https://localhost/prefix/segment?q=foobar'
|
39
|
+
it_behaves_like 'a URI builder', [:https], 'https://localhost/prefix/segment?q=foobar'
|
40
|
+
it_behaves_like 'a URI builder', [:host, 'google.com'], 'http://google.com/prefix/segment?q=foobar'
|
41
|
+
it_behaves_like 'a URI builder', [:port, 8080], 'http://localhost:8080/prefix/segment?q=foobar'
|
42
|
+
it_behaves_like 'a URI builder', [:path, '1'], 'http://localhost/prefix/segment/1?q=foobar'
|
43
|
+
it_behaves_like 'a URI builder', [:query, 'q=barfoo'], 'http://localhost/prefix/segment?q=barfoo'
|
44
|
+
it_behaves_like 'a URI builder', [:query, {q: 1, r: 2}], 'http://localhost/prefix/segment?q=1&r=2'
|
45
|
+
|
46
|
+
it_behaves_like 'a non-operational resource', :get
|
47
|
+
it_behaves_like 'a non-operational resource', :post
|
48
|
+
it_behaves_like 'a non-operational resource', :put
|
49
|
+
it_behaves_like 'a non-operational resource', :delete
|
50
|
+
it_behaves_like 'a non-operational resource', :call
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::CodecMethods do
|
4
|
+
|
5
|
+
let(:base_url) { 'http://localhost/prefix/segment?q=foobar' }
|
6
|
+
let(:base_uri) { URI(base_url) }
|
7
|
+
let(:resource) { Cardiac::Resource.new(base_uri) }
|
8
|
+
|
9
|
+
subject { resource }
|
10
|
+
|
11
|
+
describe 'decoders built with' do
|
12
|
+
subject do
|
13
|
+
lambda{|*v| builder[resource, *v] ; resource.send(:build_decoders).keys }
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
decoders = resource.send(:build_decoders)
|
18
|
+
expect(resource.reset_decoders.send(:build_decoders).keys).to eq(Cardiac::CodecMethods::DEFAULT_DECODERS)
|
19
|
+
expect(resource.decoders(*decoders.keys).send(:build_decoders).keys).to eq(decoders.keys)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :decoders do
|
23
|
+
context do
|
24
|
+
let(:builder) { lambda{|r,*v| r.decoders(*v) } }
|
25
|
+
|
26
|
+
describe '[:xml]' do
|
27
|
+
subject { super()[:xml] }
|
28
|
+
it { is_expected.to eq([:xml]) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '[:json]' do
|
32
|
+
subject { super()[:json] }
|
33
|
+
it { is_expected.to eq([:json]) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '[:xml, :json, :xml]' do
|
37
|
+
subject { super()[:xml, :json, :xml] }
|
38
|
+
it { is_expected.to eq([:xml, :json]) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context do
|
43
|
+
let(:builder) { lambda{|r,*l| l.each{|v| r.decoders(*v) } } }
|
44
|
+
|
45
|
+
describe '[[:xml]]' do
|
46
|
+
subject { super()[[:xml]] }
|
47
|
+
it { is_expected.to eq([:xml]) }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '[[:xml],[:json]]' do
|
51
|
+
subject { super()[[:xml],[:json]] }
|
52
|
+
it { is_expected.to eq([:xml, :json]) }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '[[:xml, :json], [:url_encoded, :xml]]' do
|
56
|
+
subject { super()[[:xml, :json], [:url_encoded, :xml]] }
|
57
|
+
it { is_expected.to eq([:xml, :json, :url_encoded]) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::ConfigMethods do
|
4
|
+
|
5
|
+
let(:base_url) { 'http://localhost/prefix/segment?q=foobar' }
|
6
|
+
let(:base_uri) { URI(base_url) }
|
7
|
+
let(:resource) { Cardiac::Resource.new(base_uri) }
|
8
|
+
|
9
|
+
subject { resource }
|
10
|
+
|
11
|
+
it { expect{ subject.send(:build_config) }.not_to raise_error }
|
12
|
+
|
13
|
+
describe 'config built with' do
|
14
|
+
subject do
|
15
|
+
lambda{|*v| builder[resource, *v] ; resource.send(:build_config) }
|
16
|
+
end
|
17
|
+
|
18
|
+
before :example do
|
19
|
+
@original_config = resource.send(:build_config)
|
20
|
+
end
|
21
|
+
|
22
|
+
after :each do
|
23
|
+
config = resource.send(:build_config)
|
24
|
+
resource.reconfig
|
25
|
+
expect(resource.send(:build_config)).to eq(@original_config)
|
26
|
+
resource.config.update(config)
|
27
|
+
expect(resource.send(:build_config)).to eq(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#config()' do
|
31
|
+
describe 'unwrap_client_exceptions: ...' do
|
32
|
+
let(:builder) { lambda{|r,*v| v.each{|h| r.config.update(h) } } }
|
33
|
+
|
34
|
+
describe '[{unwrap_client_exceptions: true}]' do
|
35
|
+
subject { super()[{unwrap_client_exceptions: true}] }
|
36
|
+
it { is_expected.to eq({unwrap_client_exceptions: true}) }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '[{unwrap_client_exceptions: false}]' do
|
40
|
+
subject { super()[{unwrap_client_exceptions: false}] }
|
41
|
+
it { is_expected.to eq({unwrap_client_exceptions: false}) }
|
42
|
+
end
|
43
|
+
|
44
|
+
it do
|
45
|
+
expect(resource.unwrap_client_exceptions).to be_falsey
|
46
|
+
expect(resource.config).to be_empty
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|