diff --git a/spec/controllers/kalibro_configurations_controller_spec.rb b/spec/controllers/kalibro_configurations_controller_spec.rb index dc446ba..7b53a7c 100644 --- a/spec/controllers/kalibro_configurations_controller_spec.rb +++ b/spec/controllers/kalibro_configurations_controller_spec.rb @@ -1,6 +1,14 @@ require 'rails_helper' describe KalibroConfigurationsController, :type => :controller do + + def post_method(method) + unless method == :create + post method, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params, :attributes => attributes + else + post method, :kalibro_configuration => kalibro_configuration_params, :attributes => attributes + end + end describe 'new' do before :each do @@ -19,7 +27,8 @@ describe KalibroConfigurationsController, :type => :controller do context 'with valid fields' do let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration, :with_id) } - let(:subject_params) { kalibro_configuration.to_hash } + let(:kalibro_configuration_params) { kalibro_configuration.to_hash } + let(:attributes) { {public: "1"} } before :each do KalibroConfiguration.any_instance.expects(:save).returns(true) @@ -27,7 +36,7 @@ describe KalibroConfigurationsController, :type => :controller do context 'rendering the show' do before :each do - post :create, :kalibro_configuration => subject_params + post_method :create end it 'should redirect to the show view' do @@ -37,7 +46,7 @@ describe KalibroConfigurationsController, :type => :controller do context 'without rendering the show view' do before :each do - post :create, :kalibro_configuration => subject_params + post_method :create end it { is_expected.to respond_with(:redirect) } @@ -195,8 +204,9 @@ describe KalibroConfigurationsController, :type => :controller do end describe 'update' do - let(:kalibro_configuration) {FactoryGirl.build(:kalibro_configuration, :with_id)} - let(:kalibro_configuration_params) { kalibro_configuration.to_hash } + let!(:kalibro_configuration) {FactoryGirl.build(:kalibro_configuration, :with_id)} + let!(:kalibro_configuration_params) { kalibro_configuration.to_hash } + let!(:attributes) { {public: "1"} } context 'when the user is logged in' do before do @@ -216,11 +226,12 @@ describe KalibroConfigurationsController, :type => :controller do before :each do KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns(kalibro_configuration) KalibroConfiguration.any_instance.expects(:update).with(kalibro_configuration_params).returns(true) + kalibro_configuration.expects(:attributes).returns(kalibro_configuration_attribute) end context 'rendering the show' do before :each do - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params + post_method :update end it 'should redirect to the show view' do @@ -230,7 +241,7 @@ describe KalibroConfigurationsController, :type => :controller do context 'without rendering the show view' do before :each do - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params + post_method :update end it { is_expected.to respond_with(:redirect) } @@ -242,7 +253,7 @@ describe KalibroConfigurationsController, :type => :controller do KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns(kalibro_configuration) KalibroConfiguration.any_instance.expects(:update).with(kalibro_configuration_params).returns(false) - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params + post_method :update end it { is_expected.to render_template(:edit) } @@ -251,7 +262,7 @@ describe KalibroConfigurationsController, :type => :controller do context 'when the user does not own the kalibro_configuration' do before :each do - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params + post_method :update end it { is_expected.to redirect_to kalibro_configurations_path(id: kalibro_configuration.id) } @@ -260,7 +271,7 @@ describe KalibroConfigurationsController, :type => :controller do context 'with no user logged in' do before :each do - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params + post_method :update end it { is_expected.to redirect_to new_user_session_path } diff --git a/spec/controllers/reading_groups_controller_spec.rb b/spec/controllers/reading_groups_controller_spec.rb index 9f8b70d..cb65bf5 100644 --- a/spec/controllers/reading_groups_controller_spec.rb +++ b/spec/controllers/reading_groups_controller_spec.rb @@ -12,6 +12,7 @@ describe ReadingGroupsController, :type => :controller do end describe 'create' do + let(:attributes) { {public: "1"} } before do sign_in FactoryGirl.create(:user) end @@ -26,7 +27,8 @@ describe ReadingGroupsController, :type => :controller do context 'rendering the show' do before :each do - post :create, :reading_group => subject_params + post :create, :reading_group => subject_params, :attributes => attributes + end it 'should redirect to the show view' do @@ -36,7 +38,8 @@ describe ReadingGroupsController, :type => :controller do context 'without rendering the show view' do before :each do - post :create, :reading_group => subject_params + post :create, :reading_group => subject_params, :attributes => attributes + end it { is_expected.to respond_with(:redirect) } @@ -51,7 +54,8 @@ describe ReadingGroupsController, :type => :controller do ReadingGroup.expects(:new).at_least_once.with(@subject_params).returns(@subject) ReadingGroup.any_instance.expects(:save).returns(false) - post :create, :reading_group => @subject_params + post :create, :reading_group => @subject_params, :attributes => attributes + end it { is_expected.to render_template(:new) } @@ -194,6 +198,7 @@ describe ReadingGroupsController, :type => :controller do before do @subject = FactoryGirl.build(:reading_group, :with_id) @subject_params = @subject.to_hash + @ownership = FactoryGirl.build(:reading_group_attributes, reading_group_id: @subject.id) end context 'when the user is logged in' do @@ -203,7 +208,6 @@ describe ReadingGroupsController, :type => :controller do context 'when user owns the reading group' do before do - @ownership = FactoryGirl.build(:reading_group_attributes) @ownerships = [] @ownerships.expects(:find_by_reading_group_id).with("#{@subject.id}").returns(@ownership) @@ -212,13 +216,14 @@ describe ReadingGroupsController, :type => :controller do context 'with valid fields' do before :each do + @subject.expects(:attributes).returns(@ownership) ReadingGroup.expects(:find).with(@subject.id).returns(@subject) ReadingGroup.any_instance.expects(:update).with(@subject_params).returns(true) end context 'rendering the show' do before :each do - post :update, :id => @subject.id, :reading_group => @subject_params + post :update, :id => @subject.id, :reading_group => @subject_params, :attributes => {public: @ownership.public} end it 'should redirect to the show view' do @@ -228,7 +233,8 @@ describe ReadingGroupsController, :type => :controller do context 'without rendering the show view' do before :each do - post :update, :id => @subject.id, :reading_group => @subject_params + post :update, :id => @subject.id, :reading_group => @subject_params, :attributes => {public: @ownership.public} + end it { is_expected.to respond_with(:redirect) } @@ -240,7 +246,8 @@ describe ReadingGroupsController, :type => :controller do ReadingGroup.expects(:find).with(@subject.id).returns(@subject) ReadingGroup.any_instance.expects(:update).with(@subject_params).returns(false) - post :update, :id => @subject.id, :reading_group => @subject_params + post :update, :id => @subject.id, :reading_group => @subject_params, :attributes => {public: @ownership.public} + end it { is_expected.to render_template(:edit) } @@ -249,7 +256,8 @@ describe ReadingGroupsController, :type => :controller do context 'when the user does not own the reading group' do before :each do - post :update, :id => @subject.id, :reading_group => @subject_params + post :update, :id => @subject.id, :reading_group => @subject_params, :attributes => {public: @ownership.public} + end it { is_expected.to redirect_to reading_group_path } @@ -258,7 +266,8 @@ describe ReadingGroupsController, :type => :controller do context 'with no user logged in' do before :each do - post :update, :id => @subject.id, :reading_group => @subject_params + post :update, :id => @subject.id, :reading_group => @subject_params, :attributes => {public: @ownership.public} + end it { is_expected.to redirect_to new_user_session_path } -- libgit2 0.21.2