cyrax 0.5.1.beta4 → 0.5.1.beta5
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
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDVkZDFkMDI4MWM3YWUwNjUzMDcwNGYxOTQ4ZjAxNjIyNjIyMDkxNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmY0YzA2YWNkMWYxN2NhMzZmOTA1OWRhYzY5ZWEzNGQ3NGMxZmRlYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTI3ZTkwOWFlYWNhYTdkMTMyMWRlNDlmNGE5N2RmNmE3NjNmYzc1NmZmYWVi
|
10
|
+
NThlNjU1NWFkOGZkYzZlYjEyOTE0YjkyZDVkNDFhYzlkNWRhZTU2ZDFhNzVl
|
11
|
+
NzU2MTI5ZjIxNjA3M2ViNTYxNzBjZGQyODQyZTY5MTA3NGI0MTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZThlOTFiNDQyZjM0YTVkYTc2MzIzYmI3ZjI1NzU4MDJmZGZiZmE1MGQyOWM5
|
14
|
+
Y2QxNDBhNjdkOTc5MzYxYzMwMjE3MzFkOGZkYTMzODQ0MTk3ZWM1OThkZDI5
|
15
|
+
ZWQyN2ZiZjJmYjBkMmEwZWJlMzNhMTk5MTEwN2MxYmRkNTQ5MWU=
|
@@ -8,14 +8,6 @@ module Cyrax::Extensions
|
|
8
8
|
not_allowed: 403
|
9
9
|
}
|
10
10
|
|
11
|
-
def add_error(key, value = nil)
|
12
|
-
if value.blank?
|
13
|
-
raise "Use key-value syntax for adding errors"
|
14
|
-
end
|
15
|
-
@_errors ||= {}
|
16
|
-
@_errors[key.to_sym] = value
|
17
|
-
end
|
18
|
-
|
19
11
|
def assign_resource(resource_name, resource, options = {})
|
20
12
|
if options[:decorator]
|
21
13
|
resource = Cyrax::Presenter.present(resource, options)
|
@@ -29,19 +21,31 @@ module Cyrax::Extensions
|
|
29
21
|
@_assignments[resource_name]
|
30
22
|
end
|
31
23
|
|
24
|
+
def add_error(key, value = nil)
|
25
|
+
if value.blank?
|
26
|
+
raise "Use key-value syntax for adding errors"
|
27
|
+
end
|
28
|
+
@_errors ||= {}
|
29
|
+
@_errors[key.to_sym] = value
|
30
|
+
end
|
31
|
+
|
32
32
|
def add_error_unless(key, value, condition)
|
33
33
|
add_error(key, value) unless condition
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def sync_errors_with(model)
|
37
|
+
model = model.to_model if model.respond_to?(:to_model)
|
37
38
|
if model && model.errors.messages.present?
|
39
|
+
(@_errors || {}).each do |key, value|
|
40
|
+
model.errors.add key, value unless model.errors.include?(key)
|
41
|
+
end
|
38
42
|
model.errors.messages.each do |key, value|
|
39
43
|
add_error key, value
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
def
|
48
|
+
def sync_errors_with?(model)
|
45
49
|
model = model.to_model if model.respond_to?(:to_model)
|
46
50
|
model && model.respond_to?(:errors) &&
|
47
51
|
model.errors.respond_to?(:messages)
|
@@ -78,8 +82,8 @@ module Cyrax::Extensions
|
|
78
82
|
options[:as] ||= accessor
|
79
83
|
name = options[:name] || response_name
|
80
84
|
result = result.result.to_model if result.is_a?(Cyrax::Response)
|
81
|
-
if
|
82
|
-
|
85
|
+
if sync_errors_with?(result)
|
86
|
+
sync_errors_with(result)
|
83
87
|
end
|
84
88
|
if respond_to?(:decorable?) && decorable?
|
85
89
|
options = {decorator: decorator_class}.merge(options)
|
@@ -39,7 +39,7 @@ module Cyrax::Extensions
|
|
39
39
|
# Used for :show action in controller
|
40
40
|
# @return [Cyrax::Response] response
|
41
41
|
def read(&block)
|
42
|
-
resource = find_resource(
|
42
|
+
resource = find_resource(resource_params_id)
|
43
43
|
block.call(resource) if block_given?
|
44
44
|
respond_with resource
|
45
45
|
end
|
@@ -51,7 +51,7 @@ module Cyrax::Extensions
|
|
51
51
|
# Used for :update action in controller
|
52
52
|
# @return [Cyrax::Response] response
|
53
53
|
def update(custom_attributes = nil, &block)
|
54
|
-
resource = build_resource(
|
54
|
+
resource = build_resource(resource_params_id, custom_attributes||resource_attributes)
|
55
55
|
transaction do
|
56
56
|
if save_resource(resource)
|
57
57
|
set_message(:updated)
|
@@ -66,7 +66,7 @@ module Cyrax::Extensions
|
|
66
66
|
# Used for :destroy action in controller
|
67
67
|
# @return [Cyrax::Response] response
|
68
68
|
def destroy(&block)
|
69
|
-
resource = find_resource(
|
69
|
+
resource = find_resource(resource_params_id)
|
70
70
|
transaction do
|
71
71
|
delete_resource(resource)
|
72
72
|
block.call(resource) if block_given?
|
@@ -128,5 +128,9 @@ module Cyrax::Extensions
|
|
128
128
|
block.call
|
129
129
|
end
|
130
130
|
end
|
131
|
+
|
132
|
+
def resource_params_id
|
133
|
+
params[:id]
|
134
|
+
end
|
131
135
|
end
|
132
136
|
end
|
data/lib/cyrax/version.rb
CHANGED
@@ -38,13 +38,13 @@ module Cyrax
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe '#
|
41
|
+
describe '#sync_errors_with' do
|
42
42
|
let(:messages) { [[:foo, 'bar'], [:bar, 'bazz']]}
|
43
43
|
let(:errors) { double(messages: messages)}
|
44
44
|
let(:model) { double(errors: errors) }
|
45
45
|
|
46
46
|
it 'should add errors from model error messages' do
|
47
|
-
subject.
|
47
|
+
subject.sync_errors_with(model)
|
48
48
|
subject.instance_variable_get(:@_errors).should eq({foo: 'bar', bar: 'bazz'})
|
49
49
|
end
|
50
50
|
end
|
data/spec/cyrax/resource_spec.rb
CHANGED
@@ -20,7 +20,7 @@ module Cyrax
|
|
20
20
|
it{ should respond_to(:set_message) }
|
21
21
|
it{ should respond_to(:add_error) }
|
22
22
|
it{ should respond_to(:add_error_unless) }
|
23
|
-
it{ should respond_to(:
|
23
|
+
it{ should respond_to(:sync_errors_with) }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -99,8 +99,8 @@ module Cyrax
|
|
99
99
|
context 'when resource could not be saved' do
|
100
100
|
before { resource.stub(:save).and_return(false) }
|
101
101
|
|
102
|
-
it '
|
103
|
-
subject.
|
102
|
+
it 'does not set message' do
|
103
|
+
subject.should_not_receive(:set_message).with(:created)
|
104
104
|
subject.create(params)
|
105
105
|
end
|
106
106
|
end
|
@@ -127,9 +127,9 @@ module Cyrax
|
|
127
127
|
context 'when resource could not be saved' do
|
128
128
|
before { resource.stub(:save).and_return(false) }
|
129
129
|
|
130
|
-
it '
|
131
|
-
subject.
|
132
|
-
subject.
|
130
|
+
it 'does not set message' do
|
131
|
+
subject.should_not_receive(:set_message).with(:created)
|
132
|
+
subject.create(params)
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|