cardiac 0.2.0.pre9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- it_behaves_like 'a resource declaration', 'http://localhost/', :foobar do
34
- describe '#to_url' do
35
- subject { super().to_url }
36
- it { is_expected.to eq('https://localhost/foo/bar') }
37
- end
38
-
39
- describe '#build_headers' do
40
- subject { super().send(:build_headers) }
41
- it { is_expected.to eq(default_headers.merge(:content_type => 'application/octet-stream')) }
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
- it { is_expected.not_to respond_to(:foobar) }
45
-
46
- describe '#__extension_module__' do
47
- subject { super().__extension_module__ }
48
- it { is_expected.to be_method_defined(:foobar) }
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
- describe '#base_resource' do
12
- subject { super().base_resource }
13
-
14
- it { is_expected.to be_a(::Cardiac::Resource) }
15
-
16
- describe '#to_url' do
17
- subject { super().to_url }
18
- it { is_expected.to eq('http://localhost/dummy') }
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
- subject { klass.identify(id_or_model) }
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
- it { is_expected.not_to respond_to(:find_instances) }
35
- it { is_expected.not_to respond_to(:create_instance) }
36
- it { is_expected.not_to respond_to(:identify) }
37
- it { is_expected.to respond_to(:find_instance) }
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
- expect(CGI).to receive(:escape).once.and_call_original
46
-
47
- expect(klass.identify(bad_path).to_url).to eq('http://localhost/dummy/'+good_path)
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
- it 'CGI escapes arrays' do
51
- bad_path = ['bad&','string&?']
52
- good_path = [CGI.escape('bad&'), CGI.escape('string&?')]
53
-
54
- expect(CGI).to receive(:escape).twice.and_call_original
55
-
56
- expect(klass.identify(bad_path).to_url).to eq('http://localhost/dummy/'+good_path.to_param)
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 '#with_resource()' do
61
- subject { klass.with_resource{|x| x.get } }
62
-
63
- # Mock the REST execution, using the :mock_success stubbed out response...
64
- include_context 'Client execution', :get, :success
65
-
66
- it { is_expected.to be_a(Hash) }
67
-
68
- describe "['segment']" do
69
- subject { super()['segment'] }
70
- it { is_expected.to eq({'id'=>1, 'name'=>'John Doe'}) }
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
@@ -1,3 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  # Configure Rails Environment
2
5
  ENV["RAILS_ENV"] ||= "test"
3
6
 
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.pre9
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-13 00:00:00.000000000 Z
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: 1.3.1
415
+ version: '0'
415
416
  requirements: []
416
417
  rubyforge_project: cardiac
417
418
  rubygems_version: 2.2.2