cardiac 0.2.0.pre9 → 0.2.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/README.md +35 -0
- data/lib/cardiac/declarations.rb +6 -4
- data/lib/cardiac/model/declarations.rb +4 -1
- data/lib/cardiac/resource/subresource.rb +2 -14
- data/lib/cardiac/version.rb +1 -1
- data/spec/rails-3.2/Gemfile +3 -1
- data/spec/rails-3.2/Gemfile.lock +44 -35
- data/spec/rails-3.2/app_root/log/test.log +9801 -0
- data/spec/rails-4.2/Gemfile +3 -1
- data/spec/rails-4.2/Gemfile.lock +43 -34
- data/spec/rails-4.2/app_root/log/test.log +8965 -0
- data/spec/shared/cardiac/declarations_spec.rb +39 -18
- data/spec/shared/cardiac/model/declarations_spec.rb +72 -57
- data/spec/spec_helper.rb +3 -0
- metadata +5 -4
@@ -14,9 +14,7 @@ describe Cardiac::DeclarationMethods do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
shared_examples 'a resource declaration' do |base,mock|
|
17
|
-
if mock.present?
|
18
|
-
let(:extensions) { send(:"#{mock}_extensions") }
|
19
|
-
end
|
17
|
+
let(:extensions) { send(:"#{mock}_extensions") if mock.present? }
|
20
18
|
|
21
19
|
subject { target.resource(base, &extensions) }
|
22
20
|
|
@@ -30,22 +28,45 @@ describe Cardiac::DeclarationMethods do
|
|
30
28
|
describe '#resource()' do
|
31
29
|
let(:default_headers) { {:accepts => Cardiac::RequestMethods::DEFAULT_ACCEPTS } }
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
31
|
+
context 'without extensions' do
|
32
|
+
it_behaves_like 'a resource declaration', 'http://localhost/' do
|
33
|
+
describe '#to_url' do
|
34
|
+
subject { super().to_url }
|
35
|
+
it { is_expected.to eq('http://localhost/') }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#build_headers' do
|
39
|
+
subject { super().send(:build_headers) }
|
40
|
+
it { is_expected.to eq(default_headers) }
|
41
|
+
end
|
42
|
+
|
43
|
+
it { is_expected.not_to respond_to(:foobar) }
|
44
|
+
|
45
|
+
describe '#__extension_module__' do
|
46
|
+
subject { super().__extension_module__ }
|
47
|
+
it { is_expected.to be_nil }
|
48
|
+
end
|
42
49
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with extensions' do
|
53
|
+
it_behaves_like 'a resource declaration', 'http://localhost/', :foobar do
|
54
|
+
describe '#to_url' do
|
55
|
+
subject { super().to_url }
|
56
|
+
it { is_expected.to eq('https://localhost/foo/bar') }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#build_headers' do
|
60
|
+
subject { super().send(:build_headers) }
|
61
|
+
it { is_expected.to eq(default_headers.merge(:content_type => 'application/octet-stream')) }
|
62
|
+
end
|
63
|
+
|
64
|
+
it { is_expected.not_to respond_to(:foobar) }
|
65
|
+
|
66
|
+
describe '#__extension_module__' do
|
67
|
+
subject { super().__extension_module__ }
|
68
|
+
it { is_expected.to be_method_defined(:foobar) }
|
69
|
+
end
|
49
70
|
end
|
50
71
|
end
|
51
72
|
end
|
@@ -3,72 +3,87 @@ require 'spec_helper'
|
|
3
3
|
describe Cardiac::Model::Base do
|
4
4
|
|
5
5
|
include_context 'Client responses'
|
6
|
-
|
7
|
-
let!(:klass) { Dummy }
|
8
|
-
|
9
|
-
subject { klass }
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
shared_examples 'resource declarations' do |path|
|
8
|
+
describe '#base_resource' do
|
9
|
+
subject { super().base_resource }
|
10
|
+
|
11
|
+
it { is_expected.to be_a(::Cardiac::Resource) }
|
12
|
+
|
13
|
+
describe '#to_url' do
|
14
|
+
subject { super().to_url }
|
15
|
+
it { is_expected.to eq("http://localhost/#{path}") }
|
16
|
+
end
|
19
17
|
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it { is_expected.to respond_to(:find_instances) }
|
23
|
-
it { is_expected.to respond_to(:create_instance) }
|
24
|
-
it { is_expected.to respond_to(:identify) }
|
25
|
-
it { is_expected.not_to respond_to(:find_instance) }
|
26
|
-
it { is_expected.not_to respond_to(:update_instance) }
|
27
|
-
it { is_expected.not_to respond_to(:delete_instance) }
|
28
|
-
|
29
|
-
describe '#identify' do
|
30
|
-
let(:id_or_model) { 1 }
|
31
18
|
|
32
|
-
|
19
|
+
it { is_expected.to respond_to(:find_instances) }
|
20
|
+
it { is_expected.to respond_to(:create_instance) }
|
21
|
+
it { is_expected.to respond_to(:identify) }
|
22
|
+
it { is_expected.not_to respond_to(:find_instance) }
|
23
|
+
it { is_expected.not_to respond_to(:update_instance) }
|
24
|
+
it { is_expected.not_to respond_to(:delete_instance) }
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
it { is_expected.to respond_to(:update_instance) }
|
39
|
-
it { is_expected.to respond_to(:delete_instance) }
|
40
|
-
|
41
|
-
it 'CGI escapes strings' do
|
42
|
-
bad_path = 'bad/string&?'
|
43
|
-
good_path = CGI.escape(bad_path)
|
26
|
+
describe '#identify' do
|
27
|
+
let(:id_or_model) { 1 }
|
28
|
+
|
29
|
+
subject { klass.identify(id_or_model) }
|
44
30
|
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
it { is_expected.not_to respond_to(:find_instances) }
|
32
|
+
it { is_expected.not_to respond_to(:create_instance) }
|
33
|
+
it { is_expected.not_to respond_to(:identify) }
|
34
|
+
it { is_expected.to respond_to(:find_instance) }
|
35
|
+
it { is_expected.to respond_to(:update_instance) }
|
36
|
+
it { is_expected.to respond_to(:delete_instance) }
|
37
|
+
|
38
|
+
it 'CGI escapes strings' do
|
39
|
+
bad_path = 'bad/string&?'
|
40
|
+
good_path = CGI.escape(bad_path)
|
41
|
+
|
42
|
+
expect(CGI).to receive(:escape).once.and_call_original
|
43
|
+
|
44
|
+
expect(klass.identify(bad_path).to_url).to eq("http://localhost/#{path}/#{good_path}")
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'CGI escapes arrays' do
|
48
|
+
bad_path = ['bad&','string&?']
|
49
|
+
good_path = [CGI.escape('bad&'), CGI.escape('string&?')]
|
50
|
+
|
51
|
+
expect(CGI).to receive(:escape).twice.and_call_original
|
52
|
+
|
53
|
+
expect(klass.identify(bad_path).to_url).to eq("http://localhost/#{path}/#{good_path.to_param}")
|
54
|
+
end
|
48
55
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
|
57
|
+
describe '#with_resource()' do
|
58
|
+
subject { klass.with_resource{|x| x.get } }
|
59
|
+
|
60
|
+
# Mock the REST execution, using the :mock_success stubbed out response...
|
61
|
+
include_context 'Client execution', :get, :success
|
62
|
+
|
63
|
+
it { is_expected.to be_a(Hash) }
|
64
|
+
|
65
|
+
describe "['segment']" do
|
66
|
+
subject { super()['segment'] }
|
67
|
+
it { is_expected.to eq({'id'=>1, 'name'=>'John Doe'}) }
|
68
|
+
end
|
57
69
|
end
|
58
70
|
end
|
59
|
-
|
60
|
-
describe '
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
|
72
|
+
describe 'on a base class' do
|
73
|
+
let!(:klass) { Dummy }
|
74
|
+
subject { klass }
|
75
|
+
include_examples 'resource declarations', :dummy
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'on a derived class' do
|
79
|
+
let! :klass do
|
80
|
+
Class.new(Dummy) do
|
81
|
+
resource { path '/dumber' }
|
82
|
+
end
|
71
83
|
end
|
84
|
+
|
85
|
+
subject { klass }
|
86
|
+
include_examples 'resource declarations', :dumber
|
72
87
|
end
|
73
88
|
|
74
89
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cardiac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Khoobyar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -276,6 +276,7 @@ extra_rdoc_files: []
|
|
276
276
|
files:
|
277
277
|
- .rspec
|
278
278
|
- LICENSE
|
279
|
+
- README.md
|
279
280
|
- Rakefile
|
280
281
|
- cardiac.gemspec
|
281
282
|
- lib/cardiac.rb
|
@@ -409,9 +410,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
409
410
|
version: 1.9.2
|
410
411
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
411
412
|
requirements:
|
412
|
-
- - '
|
413
|
+
- - '>='
|
413
414
|
- !ruby/object:Gem::Version
|
414
|
-
version:
|
415
|
+
version: '0'
|
415
416
|
requirements: []
|
416
417
|
rubyforge_project: cardiac
|
417
418
|
rubygems_version: 2.2.2
|