From 1fee1ffce45fba326f958172de520262f8bb8f7e Mon Sep 17 00:00:00 2001 From: Timur Valeev Date: Sat, 14 Oct 2023 05:23:02 +0000 Subject: [PATCH 1/2] Updated dev dependencies and rspec suite --- cyrax.gemspec | 5 +- spec/cyrax/decorator_spec.rb | 2 +- spec/cyrax/extensions/has_resource_spec.rb | 24 ++++----- spec/cyrax/extensions/has_response_spec.rb | 32 ++++++------ spec/cyrax/extensions/has_service_spec.rb | 18 +++---- spec/cyrax/resource_spec.rb | 58 +++++++++++----------- spec/cyrax/response_spec.rb | 6 +-- spec/cyrax/serializer_spec.rb | 10 ++-- spec/spec_helper.rb | 3 +- 9 files changed, 80 insertions(+), 78 deletions(-) diff --git a/cyrax.gemspec b/cyrax.gemspec index 43873f9..2bcfc08 100644 --- a/cyrax.gemspec +++ b/cyrax.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |spec| 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 diff --git a/spec/cyrax/decorator_spec.rb b/spec/cyrax/decorator_spec.rb index b04e980..10afa25 100644 --- a/spec/cyrax/decorator_spec.rb +++ b/spec/cyrax/decorator_spec.rb @@ -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 diff --git a/spec/cyrax/extensions/has_resource_spec.rb b/spec/cyrax/extensions/has_resource_spec.rb index b9c00cc..de239a8 100644 --- a/spec/cyrax/extensions/has_resource_spec.rb +++ b/spec/cyrax/extensions/has_resource_spec.rb @@ -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 @@ -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 diff --git a/spec/cyrax/extensions/has_response_spec.rb b/spec/cyrax/extensions/has_response_spec.rb index 8c6062b..f15fa33 100644 --- a/spec/cyrax/extensions/has_response_spec.rb +++ b/spec/cyrax/extensions/has_response_spec.rb @@ -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 @@ -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 diff --git a/spec/cyrax/extensions/has_service_spec.rb b/spec/cyrax/extensions/has_service_spec.rb index 122aa39..214167b 100644 --- a/spec/cyrax/extensions/has_service_spec.rb +++ b/spec/cyrax/extensions/has_service_spec.rb @@ -19,16 +19,16 @@ 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 @@ -36,24 +36,24 @@ class BaseWithService < Cyrax::Base 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 diff --git a/spec/cyrax/resource_spec.rb b/spec/cyrax/resource_spec.rb index d84519f..b5e3b36 100644 --- a/spec/cyrax/resource_spec.rb +++ b/spec/cyrax/resource_spec.rb @@ -28,84 +28,84 @@ module Cyrax let(:resource) { double.as_null_object } let(:collection) { [double] } before do - subject.stub(:params).and_return({id:123}) - subject.stub(:find_resource).and_return(resource) + allow(subject).to receive(:params).and_return({id:123}) + allow(subject).to receive(:find_resource).and_return(resource) subject.class.send :resource, :foo end describe '#read_all' do it 'responds with decorated collection' do - subject.should_receive(:build_collection).and_return(collection) - subject.should_receive(:respond_with).with(collection, name: 'foos', present: :collection) + expect(subject).to receive(:build_collection).and_return(collection) + expect(subject).to receive(:respond_with).with(collection, name: 'foos', present: :collection) subject.read_all end end describe '#build' do it 'responds with resource' do - subject.should_receive(:build_resource).with(nil).and_return(resource) - subject.should_receive(:respond_with).with(resource) + expect(subject).to receive(:build_resource).with(nil).and_return(resource) + expect(subject).to receive(:respond_with).with(resource) subject.build end end describe '#edit' do it 'responds with resource' do - subject.should_receive(:find_resource) - subject.should_receive(:respond_with).with(resource) + expect(subject).to receive(:find_resource) + expect(subject).to receive(:respond_with).with(resource) subject.edit end end describe '#read' do it 'responds with resource' do - subject.should_receive(:find_resource) - subject.should_receive(:respond_with).with(resource) + expect(subject).to receive(:find_resource) + expect(subject).to receive(:respond_with).with(resource) subject.read end end describe '#destroy' do it 'responds with resource' do - subject.should_receive(:find_resource) - subject.should_receive(:respond_with).with(resource) + expect(subject).to receive(:find_resource) + expect(subject).to receive(:respond_with).with(resource) subject.destroy end it 'destroys resource' do - resource.should_receive(:destroy) + expect(resource).to receive(:destroy) subject.destroy end end describe '#create' do let(:params) { {foo: 'bar'} } - before { subject.stub(:build_resource).and_return(resource) } + before { allow(subject).to receive(:build_resource).and_return(resource) } it 'responds with resource' do - subject.should_receive(:build_resource).with(nil, params) - subject.should_receive(:respond_with).with(resource) + expect(subject).to receive(:build_resource).with(nil, params) + expect(subject).to receive(:respond_with).with(resource) subject.create(params) end context 'when resource successfully saved' do - before { resource.stub(:save).and_return(true) } + before { allow(resource).to receive(:save).and_return(true) } it 'sets message' do - subject.should_receive(:set_message).with(:created) + expect(subject).to receive(:set_message).with(:created) subject.create(params) end end context 'when resource could not be saved' do - before { resource.stub(:save).and_return(false) } + before { allow(resource).to receive(:save).and_return(false) } it 'does not set message' do - subject.should_not_receive(:set_message).with(:created) + expect(subject).to_not receive(:set_message).with(:created) subject.create(params) end it "sets 422 status" do - subject.should_receive(:set_status).with(422) + expect(subject).to receive(:set_status).with(422) subject.create(params) end end @@ -113,32 +113,32 @@ module Cyrax describe '#update' do let(:params) { {foo: 'bar'} } - before { subject.stub(:build_resource).and_return(resource) } + before { allow(subject).to receive(:build_resource).and_return(resource) } it 'responds with resource' do - subject.should_receive(:build_resource).with(123, params) - subject.should_receive(:respond_with).with(resource) + expect(subject).to receive(:build_resource).with(123, params) + expect(subject).to receive(:respond_with).with(resource) subject.update(params) end context 'when resource successfully saved' do - before { resource.stub(:save).and_return(true) } + before { allow(resource).to receive(:save).and_return(true) } it 'sets message' do - subject.should_receive(:set_message).with(:updated) + expect(subject).to receive(:set_message).with(:updated) subject.update(params) end end context 'when resource could not be saved' do - before { resource.stub(:save).and_return(false) } + before { allow(resource).to receive(:save).and_return(false) } it 'does not set message' do - subject.should_not_receive(:set_message).with(:created) + expect(subject).to_not receive(:set_message).with(:created) subject.update(params) end it "sets 422 status" do - subject.should_receive(:set_status).with(422) + expect(subject).to receive(:set_status).with(422) subject.update(params) end end diff --git a/spec/cyrax/response_spec.rb b/spec/cyrax/response_spec.rb index e6284fd..6e4aa66 100644 --- a/spec/cyrax/response_spec.rb +++ b/spec/cyrax/response_spec.rb @@ -78,13 +78,13 @@ module Cyrax describe '#has_error?' do context 'when there are no errors' do before { subject.with_errors({}) } - specify { subject.has_error?(:foo).should be(false) } + specify { expect(subject.has_error?(:foo)).to be(false) } end context 'when there are errors' do before { subject.with_errors({foo: 'some', bar: 'errors'}) } - specify { subject.has_error?(:foo).should be(true) } - specify { subject.has_error?(:foo1).should be(false) } + specify { expect(subject.has_error?(:foo)).to be(true) } + specify { expect(subject.has_error?(:foo1)).to be(false) } end end diff --git a/spec/cyrax/serializer_spec.rb b/spec/cyrax/serializer_spec.rb index 531c978..64ed5e8 100644 --- a/spec/cyrax/serializer_spec.rb +++ b/spec/cyrax/serializer_spec.rb @@ -31,11 +31,11 @@ module Cyrax subject { FooSerializer.new(serializable).serialize } it 'should serialize object' do - subject[:name].should eq('me') - subject[:some][:foo].should eq('2342') - subject[:another][:another_foo].should eq('1234') - subject[:empty_relation_one].should eq(nil) - subject[:empty_relation_many].should eq([]) + expect(subject[:name]).to eq('me') + expect(subject[:some][:foo]).to eq('2342') + expect(subject[:another][:another_foo]).to eq('1234') + expect(subject[:empty_relation_one]).to eq(nil) + expect(subject[:empty_relation_many]).to eq([]) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fed0435..eb41450 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,4 +3,5 @@ require 'simplecov' SimpleCov.start end -require 'cyrax' \ No newline at end of file +require 'cyrax' +require 'rspec/its' From cb128a9dec6eee89e87a98812087ea6b399b3f07 Mon Sep 17 00:00:00 2001 From: Timur Valeev Date: Sat, 14 Oct 2023 05:31:10 +0000 Subject: [PATCH 2/2] Update version of active_model & active_support to 6.0+ and bump version --- CHANGELOG.md | 5 ++++- README.md | 6 +++++- cyrax.gemspec | 4 ++-- lib/cyrax/version.rb | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b439588..e2eb1a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 \ No newline at end of file +* respond_with logic changed, now it works with Presenter diff --git a/README.md b/README.md index c54a96e..e034a44 100644 --- a/README.md +++ b/README.md @@ -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' @@ -30,4 +34,4 @@ Look at `example` folder. Hope, you'll enjoy Cyrax! -Cheers, [Droid Labs](http://droidlabs.pro). \ No newline at end of file +Cheers, [Droid Labs](http://droidlabs.pro). diff --git a/cyrax.gemspec b/cyrax.gemspec index 2bcfc08..2702efd 100644 --- a/cyrax.gemspec +++ b/cyrax.gemspec @@ -16,8 +16,8 @@ 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" diff --git a/lib/cyrax/version.rb b/lib/cyrax/version.rb index a13356a..eebc9bf 100644 --- a/lib/cyrax/version.rb +++ b/lib/cyrax/version.rb @@ -1,3 +1,3 @@ module Cyrax - VERSION = "0.9.0" + VERSION = "0.10.0" end