Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
== 0.10.0
* POTENTIAL BREAKING CHANGE: activesupport & activemodel dependency updated to > 6.0

== 0.9.0
* BREAKING CHANGE: "master" branch is replaced with 0.5 version branch
* BREAKING CHANGE: Replace deprecated before_filter to before_action for rails 5+ support
Expand Down Expand Up @@ -78,4 +81,4 @@
=== 0.2.3
* Added collection decorator, to decorate collections with decorator use Decorator.decorate_collection(collection)
* Added presenter logic
* respond_with logic changed, now it works with Presenter
* respond_with logic changed, now it works with Presenter
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Cyrax is microframework to build layered architecture, one of the core concepts

Add this line to your Gemfile.

Rails 6:

gem 'cyrax', '~> 0.10.0'

Rails 5:

gem 'cyrax', '~> 0.9.0'
Expand All @@ -30,4 +34,4 @@ Look at `example` folder.

Hope, you'll enjoy Cyrax!

Cheers, [Droid Labs](http://droidlabs.pro).
Cheers, [Droid Labs](http://droidlabs.pro).
9 changes: 5 additions & 4 deletions cyrax.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ Gem::Specification.new do |spec|

spec.add_dependency "active_model_serializers"
spec.add_dependency "activemodel-serializers-xml"
spec.add_dependency "activesupport", '~> 5.0'
spec.add_dependency "activemodel", '~> 5.0'
spec.add_dependency "activesupport", '~> 6.0'
spec.add_dependency "activemodel", '~> 6.0'
spec.add_dependency "has_active_logger"
spec.add_dependency "multi_json"

spec.add_development_dependency "sqlite3", '~> 1.5.4'
spec.add_development_dependency "rspec", '~> 2.99.0'
spec.add_development_dependency "sqlite3", '~> 1.5'
spec.add_development_dependency "rspec", '~> 3.12'
spec.add_development_dependency "rspec-its", '~> 1.3'
end
2 changes: 1 addition & 1 deletion lib/cyrax/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Cyrax
VERSION = "0.9.0"
VERSION = "0.10.0"
end
2 changes: 1 addition & 1 deletion spec/cyrax/decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Cyrax
its(:resource) { should eq(decorable) }

it 'should translate missing methods to decorable' do
subject.foo.should eq('bar')
expect(subject.foo).to eq('bar')
end

it 'should not translate missing methods' do
Expand Down
24 changes: 12 additions & 12 deletions spec/cyrax/extensions/has_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ class BaseWithResource < Cyrax::Base
end

describe '#resource_scope' do
before { subject.stub(:resource_class).and_return(Foo) }
before { allow(subject).to receive(:resource_class).and_return(Foo) }
its(:resource_scope) { should eq(Foo) }
end

describe '#resource_attributes' do
let(:dirty_resource_attributes) { double }
before { subject.stub(:dirty_resource_attributes).and_return(dirty_resource_attributes)}
before { allow(subject).to receive(:dirty_resource_attributes).and_return(dirty_resource_attributes)}
it 'filters dirty attributes' do
subject.should_receive(:filter_attributes).with(dirty_resource_attributes)
expect(subject).to receive(:filter_attributes).with(dirty_resource_attributes)
subject.resource_attributes
end
end
Expand All @@ -75,33 +75,33 @@ class BaseWithResource < Cyrax::Base
describe '#dirty_resource_attributes' do
context 'when params are present' do
it 'should return from params by resource_name' do
subject.stub(:resource_name).and_return(:foo)
subject.stub(:params).and_return({foo: {bar: 'bazz'}})
subject.send(:dirty_resource_attributes).should eq({bar: 'bazz'})
allow(subject).to receive(:resource_name).and_return(:foo)
allow(subject).to receive(:params).and_return({foo: {bar: 'bazz'}})
expect(subject.send(:dirty_resource_attributes)).to eq({bar: 'bazz'})
end
end
context 'when there are no params' do
it 'should return empty hash' do
subject.stub(:resource_name).and_return(:foo)
subject.stub(:params).and_return({})
subject.send(:dirty_resource_attributes).should eq({})
allow(subject).to receive(:resource_name).and_return(:foo)
allow(subject).to receive(:params).and_return({})
expect(subject.send(:dirty_resource_attributes)).to eq({})
end
end
end
describe '#default_resource_attributes' do
it 'should return empty hash by default' do
subject.send(:default_resource_attributes).should eq({})
expect(subject.send(:default_resource_attributes)).to eq({})
end
end

describe '#filter_attributes' do
it 'should return supplied attributes by default' do
subject.send(:filter_attributes, {foo: 'bar'}).should eq({foo: 'bar'})
expect(subject.send(:filter_attributes, {foo: 'bar'})).to eq({foo: 'bar'})
end
it 'should return blank attributes by default for strong_paramters=true' do
Cyrax.strong_parameters = true
params = StrongParameters.new(foo: 'bar')
subject.send(:filter_attributes, params).should eq({})
expect(subject.send(:filter_attributes, params)).to eq({})
end
end
end
Expand Down
32 changes: 16 additions & 16 deletions spec/cyrax/extensions/has_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ class BaseWithResponse < Cyrax::Base
describe Cyrax::Extensions::HasResponse do
subject { BaseWithResponse.new }
before do
subject.stub(:decorable?).and_return(false)
subject.stub(:decorator_class).and_return(nil)
allow(subject).to receive(:decorable?).and_return(false)
allow(subject).to receive(:decorator_class).and_return(nil)
end

describe '#set_message' do
it 'should set message' do
subject.set_message('foo')
subject.instance_variable_get(:@_message).should eq('foo')
expect(subject.instance_variable_get(:@_message)).to eq('foo')
end
end

describe '#add_error' do
it 'should add error' do
subject.add_error(:foo, 'bar')
subject.instance_variable_get(:@_errors).has_key?(:foo).should be(true)
expect(subject.instance_variable_get(:@_errors).has_key?(:foo)).to be(true)
end
end

describe '#add_error_unless' do
it 'should add error when condition false' do
subject.add_error_unless(:foo, 'bar', 1==0)
subject.instance_variable_get(:@_errors).has_key?(:foo).should be(true)
expect(subject.instance_variable_get(:@_errors).has_key?(:foo)).to be(true)
end

it 'should not add error when condition true' do
subject.add_error_unless(:foo, 'bar', 1==1)
subject.instance_variable_get(:@_errors).should be_nil
expect(subject.instance_variable_get(:@_errors)).to be_nil
end
end

Expand All @@ -45,35 +45,35 @@ class BaseWithResponse < Cyrax::Base

it 'should add errors from model error messages' do
subject.sync_errors_with(model)
subject.instance_variable_get(:@_errors).should eq({foo: 'bar', bar: 'bazz'})
expect(subject.instance_variable_get(:@_errors)).to eq({foo: 'bar', bar: 'bazz'})
end
end

describe '#assign_resource' do
it 'should set assignments' do
subject.assign_resource('foo', 'bar')
subject.instance_variable_get(:@_assignments).should eq({foo: 'bar'})
expect(subject.instance_variable_get(:@_assignments)).to eq({foo: 'bar'})
end
end

describe '#respond_with' do
before { subject.stub(:response_name).and_return(:foo) }
before { allow(subject).to receive(:response_name).and_return(:foo) }
it 'calls Cyrax::Response' do
Cyrax::Response.should_receive(:new).with(:foo, 'bar', {as: nil, assignments: nil}).and_return(double.as_null_object)
expect(Cyrax::Response).to receive(:new).with(:foo, 'bar', {as: nil, assignments: nil}).and_return(double.as_null_object)
subject.respond_with('bar')
end

it 'should return Cyrax::Response instance' do
subject.respond_with('bar').should be_a_kind_of(Cyrax::Response)
expect(subject.respond_with('bar')).to be_a_kind_of(Cyrax::Response)
end

it 'should assign message, errors and additional assignments to response object' do
response = double
Cyrax::Response.should_receive(:new).and_return(response)
response.should_receive(:message=)
response.should_receive(:errors=)
response.should_receive(:assignments=)
response.should_receive(:status=)
expect(Cyrax::Response).to receive(:new).and_return(response)
expect(response).to receive(:message=)
expect(response).to receive(:errors=)
expect(response).to receive(:assignments=)
expect(response).to receive(:status=)
subject.respond_with('bar')
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/cyrax/extensions/has_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,41 @@ class BaseWithService < Cyrax::Base

describe 'instance methods' do
describe '#build_collection' do
before { subject.stub(:resource_scope).and_return(Foo) }
before { allow(subject).to receive(:resource_scope).and_return(Foo) }
its(:build_collection) { should eq(Foo) }
end

describe '#find_resource' do
let(:resource_scope) { double }
before { subject.stub(:resource_scope).and_return(resource_scope) }
before { allow(subject).to receive(:resource_scope).and_return(resource_scope) }
it 'finds resource by id' do
allow_message_expectations_on_nil
resource_scope.should_receive(:find).with(123)
expect(resource_scope).to receive(:find).with(123)
subject.find_resource(123)
end
end

describe '#build_resource' do
context 'when id is nil' do
let(:resource_scope) { double }
before { subject.stub(:resource_scope).and_return(resource_scope) }
before { subject.stub(:default_resource_attributes).and_return({}) }
before { allow(subject).to receive(:resource_scope).and_return(resource_scope) }
before { allow(subject).to receive(:default_resource_attributes).and_return({}) }
it 'initializes new object' do
allow_message_expectations_on_nil
resource_scope.should_receive(:new).with({foo: 'bar'})
expect(resource_scope).to receive(:new).with({foo: 'bar'})
subject.build_resource(nil, {foo: 'bar'})
end
end
context 'when id is present' do
let(:resource) { double.as_null_object }
it 'finds resource' do
subject.should_receive(:find_resource).with(123).and_return(resource)
expect(subject).to receive(:find_resource).with(123).and_return(resource)
subject.build_resource(123, {foo: 'bar'})
end

it 'assigns provided attributes' do
subject.stub(:find_resource).and_return(resource)
resource.should_receive(:attributes=).with({foo: 'bar'})
allow(subject).to receive(:find_resource).and_return(resource)
expect(resource).to receive(:attributes=).with({foo: 'bar'})
subject.build_resource(123, {foo: 'bar'})
end
end
Expand Down
Loading