cyrax 0.5.13 → 0.6.0.beta
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 +14 -6
- data/lib/cyrax.rb +2 -9
- data/lib/cyrax/decorator.rb +0 -17
- data/lib/cyrax/extensions/has_decorator.rb +9 -9
- data/lib/cyrax/extensions/has_repository.rb +43 -0
- data/lib/cyrax/extensions/has_resource.rb +23 -32
- data/lib/cyrax/extensions/has_response.rb +0 -1
- data/lib/cyrax/extensions/has_serializer.rb +9 -9
- data/lib/cyrax/extensions/has_service.rb +26 -59
- data/lib/cyrax/helpers/controller.rb +1 -1
- data/lib/cyrax/presenter.rb +1 -1
- data/lib/cyrax/repository.rb +102 -0
- data/lib/cyrax/resource.rb +1 -0
- data/lib/cyrax/response.rb +3 -8
- data/lib/cyrax/serializer.rb +0 -27
- data/lib/cyrax/serializers/scope.rb +4 -18
- data/lib/cyrax/version.rb +1 -1
- data/spec/cyrax/extensions/has_decorator_spec.rb +5 -5
- data/spec/cyrax/extensions/has_repository_spec.rb +28 -0
- data/spec/cyrax/extensions/has_resource_spec.rb +6 -15
- data/spec/cyrax/extensions/has_response_spec.rb +1 -1
- data/spec/cyrax/extensions/has_service_spec.rb +0 -43
- data/spec/cyrax/repository_spec.rb +72 -0
- data/spec/cyrax/resource_spec.rb +21 -35
- data/spec/cyrax/serializer_spec.rb +2 -13
- metadata +28 -36
data/spec/cyrax/resource_spec.rb
CHANGED
@@ -10,11 +10,7 @@ module Cyrax
|
|
10
10
|
it{ should respond_to(:params) }
|
11
11
|
it{ should respond_to(:resource_name) }
|
12
12
|
it{ should respond_to(:resource_class) }
|
13
|
-
it{ should respond_to(:resource_scope) }
|
14
13
|
it{ should respond_to(:resource_attributes) }
|
15
|
-
it{ should respond_to(:build_resource) }
|
16
|
-
it{ should respond_to(:build_collection) }
|
17
|
-
it{ should respond_to(:find_resource) }
|
18
14
|
it{ should respond_to(:assign_resource) }
|
19
15
|
it{ should respond_to(:respond_with) }
|
20
16
|
it{ should respond_to(:set_message) }
|
@@ -25,17 +21,19 @@ module Cyrax
|
|
25
21
|
end
|
26
22
|
|
27
23
|
subject { Cyrax::Resource.new }
|
24
|
+
let(:repository) { double }
|
28
25
|
let(:resource) { double.as_null_object }
|
29
26
|
let(:collection) { [double] }
|
30
27
|
before do
|
31
28
|
subject.stub(:params).and_return({id:123})
|
32
|
-
subject.stub(:
|
29
|
+
subject.stub(:repository).and_return(repository)
|
30
|
+
repository.stub(:find).and_return(resource)
|
33
31
|
subject.class.send :resource, :foo
|
34
32
|
end
|
35
33
|
|
36
34
|
describe '#read_all' do
|
37
35
|
it 'responds with decorated collection' do
|
38
|
-
|
36
|
+
repository.should_receive(:find_all).and_return(collection)
|
39
37
|
subject.should_receive(:respond_with).with(collection, name: 'foos', present: :collection)
|
40
38
|
subject.read_all
|
41
39
|
end
|
@@ -43,7 +41,7 @@ module Cyrax
|
|
43
41
|
|
44
42
|
describe '#build' do
|
45
43
|
it 'responds with resource' do
|
46
|
-
|
44
|
+
repository.should_receive(:build).with(nil).and_return(resource)
|
47
45
|
subject.should_receive(:respond_with).with(resource)
|
48
46
|
subject.build
|
49
47
|
end
|
@@ -51,7 +49,7 @@ module Cyrax
|
|
51
49
|
|
52
50
|
describe '#edit' do
|
53
51
|
it 'responds with resource' do
|
54
|
-
|
52
|
+
repository.should_receive(:find)
|
55
53
|
subject.should_receive(:respond_with).with(resource)
|
56
54
|
subject.edit
|
57
55
|
end
|
@@ -59,36 +57,33 @@ module Cyrax
|
|
59
57
|
|
60
58
|
describe '#read' do
|
61
59
|
it 'responds with resource' do
|
62
|
-
|
60
|
+
repository.should_receive(:find)
|
63
61
|
subject.should_receive(:respond_with).with(resource)
|
64
62
|
subject.read
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
66
|
describe '#destroy' do
|
69
|
-
it 'responds with resource' do
|
70
|
-
|
67
|
+
it 'destroys resource and responds with resource' do
|
68
|
+
repository.should_receive(:find)
|
69
|
+
repository.should_receive(:delete)
|
71
70
|
subject.should_receive(:respond_with).with(resource)
|
72
71
|
subject.destroy
|
73
72
|
end
|
74
|
-
|
75
|
-
it 'destroys resource' do
|
76
|
-
resource.should_receive(:destroy)
|
77
|
-
subject.destroy
|
78
|
-
end
|
79
73
|
end
|
80
74
|
|
81
75
|
describe '#create' do
|
82
76
|
let(:params) { {foo: 'bar'} }
|
83
|
-
before {
|
77
|
+
before { repository.stub(:build).and_return(resource) }
|
84
78
|
it 'responds with resource' do
|
85
|
-
|
79
|
+
repository.should_receive(:save).with(resource)
|
80
|
+
repository.should_receive(:build).with(nil, params)
|
86
81
|
subject.should_receive(:respond_with).with(resource)
|
87
82
|
subject.create(params)
|
88
83
|
end
|
89
84
|
|
90
85
|
context 'when resource successfully saved' do
|
91
|
-
before {
|
86
|
+
before { repository.stub(:save).and_return(true) }
|
92
87
|
|
93
88
|
it 'sets message' do
|
94
89
|
subject.should_receive(:set_message).with(:created)
|
@@ -97,31 +92,27 @@ module Cyrax
|
|
97
92
|
end
|
98
93
|
|
99
94
|
context 'when resource could not be saved' do
|
100
|
-
before {
|
95
|
+
before { repository.stub(:save).and_return(false) }
|
101
96
|
|
102
97
|
it 'does not set message' do
|
103
98
|
subject.should_not_receive(:set_message).with(:created)
|
104
99
|
subject.create(params)
|
105
100
|
end
|
106
|
-
|
107
|
-
it "sets 422 status" do
|
108
|
-
subject.should_receive(:set_status).with(422)
|
109
|
-
subject.create(params)
|
110
|
-
end
|
111
101
|
end
|
112
102
|
end
|
113
103
|
|
114
104
|
describe '#update' do
|
115
105
|
let(:params) { {foo: 'bar'} }
|
116
|
-
before {
|
106
|
+
before { repository.stub(:build).and_return(resource) }
|
117
107
|
it 'responds with resource' do
|
118
|
-
|
108
|
+
repository.should_receive(:build).with(123, params)
|
109
|
+
repository.should_receive(:save).with(resource)
|
119
110
|
subject.should_receive(:respond_with).with(resource)
|
120
111
|
subject.update(params)
|
121
112
|
end
|
122
113
|
|
123
114
|
context 'when resource successfully saved' do
|
124
|
-
before {
|
115
|
+
before { repository.stub(:save).and_return(true) }
|
125
116
|
|
126
117
|
it 'sets message' do
|
127
118
|
subject.should_receive(:set_message).with(:updated)
|
@@ -130,16 +121,11 @@ module Cyrax
|
|
130
121
|
end
|
131
122
|
|
132
123
|
context 'when resource could not be saved' do
|
133
|
-
before {
|
124
|
+
before { repository.stub(:save).and_return(false) }
|
134
125
|
|
135
126
|
it 'does not set message' do
|
136
127
|
subject.should_not_receive(:set_message).with(:created)
|
137
|
-
subject.
|
138
|
-
end
|
139
|
-
|
140
|
-
it "sets 422 status" do
|
141
|
-
subject.should_receive(:set_status).with(422)
|
142
|
-
subject.update(params)
|
128
|
+
subject.create(params)
|
143
129
|
end
|
144
130
|
end
|
145
131
|
end
|
@@ -8,25 +8,16 @@ class FooSerializer < Cyrax::Serializer
|
|
8
8
|
relation :another do
|
9
9
|
attributes :another_foo, :another_bar
|
10
10
|
end
|
11
|
-
relation :empty_relation_many do
|
12
|
-
attributes :another_foo, :another_bar
|
13
|
-
end
|
14
|
-
relation :empty_relation_one do
|
15
|
-
attributes :another_foo, :another_bar
|
16
|
-
end
|
17
11
|
end
|
18
12
|
|
19
13
|
module Cyrax
|
20
14
|
describe FooSerializer do
|
21
|
-
let(:serializable) {
|
15
|
+
let(:serializable) {
|
22
16
|
double(
|
23
17
|
name: 'me',
|
24
18
|
foo: '2342',
|
25
19
|
bar: '4223',
|
26
|
-
another: double(another_foo: '1234', another_bar: '1234')
|
27
|
-
empty_relation_one: nil,
|
28
|
-
empty_relation_many: []
|
29
|
-
)
|
20
|
+
another: double(another_foo: '1234', another_bar: '1234'))
|
30
21
|
}
|
31
22
|
subject { FooSerializer.new(serializable).serialize }
|
32
23
|
|
@@ -34,8 +25,6 @@ module Cyrax
|
|
34
25
|
subject[:name].should eq('me')
|
35
26
|
subject[:some][:foo].should eq('2342')
|
36
27
|
subject[:another][:another_foo].should eq('1234')
|
37
|
-
subject[:empty_relation_one].should eq(nil)
|
38
|
-
subject[:empty_relation_many].should eq([])
|
39
28
|
end
|
40
29
|
end
|
41
30
|
end
|
metadata
CHANGED
@@ -1,112 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyrax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droidlabs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: has_active_logger
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: multi_json
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
52
|
+
- - ! '>='
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: sqlite3
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- -
|
59
|
+
- - ! '>='
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: '0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- -
|
66
|
+
- - ! '>='
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- -
|
73
|
+
- - ! '>='
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
75
|
+
version: '0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- -
|
80
|
+
- - ! '>='
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: '0'
|
97
83
|
description: Small library for adding service layer to Rails projects
|
98
84
|
email:
|
99
85
|
executables: []
|
100
86
|
extensions: []
|
101
87
|
extra_rdoc_files: []
|
102
88
|
files:
|
103
|
-
- LICENSE.txt
|
104
|
-
- README.md
|
105
|
-
- Rakefile
|
106
|
-
- lib/cyrax.rb
|
107
89
|
- lib/cyrax/base.rb
|
108
90
|
- lib/cyrax/decorator.rb
|
109
91
|
- lib/cyrax/extensions/has_decorator.rb
|
92
|
+
- lib/cyrax/extensions/has_repository.rb
|
110
93
|
- lib/cyrax/extensions/has_resource.rb
|
111
94
|
- lib/cyrax/extensions/has_response.rb
|
112
95
|
- lib/cyrax/extensions/has_serializer.rb
|
@@ -115,18 +98,25 @@ files:
|
|
115
98
|
- lib/cyrax/presenter.rb
|
116
99
|
- lib/cyrax/presenters/base_collection.rb
|
117
100
|
- lib/cyrax/presenters/decorated_collection.rb
|
101
|
+
- lib/cyrax/repository.rb
|
118
102
|
- lib/cyrax/resource.rb
|
119
103
|
- lib/cyrax/response.rb
|
120
104
|
- lib/cyrax/serializer.rb
|
121
105
|
- lib/cyrax/serializers/scope.rb
|
122
106
|
- lib/cyrax/version.rb
|
123
107
|
- lib/cyrax/wrapper.rb
|
108
|
+
- lib/cyrax.rb
|
109
|
+
- LICENSE.txt
|
110
|
+
- Rakefile
|
111
|
+
- README.md
|
124
112
|
- spec/cyrax/base_spec.rb
|
125
113
|
- spec/cyrax/decorator_spec.rb
|
126
114
|
- spec/cyrax/extensions/has_decorator_spec.rb
|
115
|
+
- spec/cyrax/extensions/has_repository_spec.rb
|
127
116
|
- spec/cyrax/extensions/has_resource_spec.rb
|
128
117
|
- spec/cyrax/extensions/has_response_spec.rb
|
129
118
|
- spec/cyrax/extensions/has_service_spec.rb
|
119
|
+
- spec/cyrax/repository_spec.rb
|
130
120
|
- spec/cyrax/resource_spec.rb
|
131
121
|
- spec/cyrax/response_spec.rb
|
132
122
|
- spec/cyrax/serializer_spec.rb
|
@@ -141,17 +131,17 @@ require_paths:
|
|
141
131
|
- lib
|
142
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
133
|
requirements:
|
144
|
-
- -
|
134
|
+
- - ! '>='
|
145
135
|
- !ruby/object:Gem::Version
|
146
136
|
version: '0'
|
147
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
138
|
requirements:
|
149
|
-
- -
|
139
|
+
- - ! '>'
|
150
140
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
141
|
+
version: 1.3.1
|
152
142
|
requirements: []
|
153
143
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.0.5
|
155
145
|
signing_key:
|
156
146
|
specification_version: 4
|
157
147
|
summary: Small library for adding service layer to Rails projects
|
@@ -159,9 +149,11 @@ test_files:
|
|
159
149
|
- spec/cyrax/base_spec.rb
|
160
150
|
- spec/cyrax/decorator_spec.rb
|
161
151
|
- spec/cyrax/extensions/has_decorator_spec.rb
|
152
|
+
- spec/cyrax/extensions/has_repository_spec.rb
|
162
153
|
- spec/cyrax/extensions/has_resource_spec.rb
|
163
154
|
- spec/cyrax/extensions/has_response_spec.rb
|
164
155
|
- spec/cyrax/extensions/has_service_spec.rb
|
156
|
+
- spec/cyrax/repository_spec.rb
|
165
157
|
- spec/cyrax/resource_spec.rb
|
166
158
|
- spec/cyrax/response_spec.rb
|
167
159
|
- spec/cyrax/serializer_spec.rb
|