diff --git a/spec/controllers/articles_controller_spec.rb b/spec/controllers/articles_controller_spec.rb index e2840dc..7d53472 100644 --- a/spec/controllers/articles_controller_spec.rb +++ b/spec/controllers/articles_controller_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ArticlesController, type: :controller do let!(:category) { create(:category, domain: Category::DOMAIN_NEWS) } let!(:params) { FactoryBot.attributes_for(:article).merge!(category_id: category.id) } - let!(:invalid_params) { params.merge!(:title => (0..150).map { (65 + rand(26)).chr }.join) } + let!(:invalid_params) { params.merge(:title => (0..150).map { (65 + rand(26)).chr }.join) } let!(:article) { create(:article, category_id: category.id, user_id: admin.id) } let!(:admin) { create(:user, :admin) } let!(:user) { create(:user) } @@ -53,6 +53,10 @@ RSpec.describe ArticlesController, type: :controller do end context 'POST' do + before(:each) do + expect(:params).not_to eq(:invalid_params) + end + describe 'with valid values' do it "creates the model" do login_admin @@ -77,10 +81,10 @@ RSpec.describe ArticlesController, type: :controller do expect(Article.count).to eq(count) end - it "redirects correctly" do + it "renders :new" do login_admin post :create, params: {:article => invalid_params} - expect(response).to redirect_to(article_path(Article.last)) + expect(response).to render_template("new") end end end @@ -109,10 +113,10 @@ RSpec.describe ArticlesController, type: :controller do expect(Article.find(article.id).attributes).to eq(article.attributes) end - it "redirects correctly" do + it "renders :edit" do login_admin - post :create, params: {:article => invalid_params} - expect(response).to redirect_to(article_path(Article.last)) + put :update, params: {:id => article.id, :article => invalid_params} + expect(response).to render_template("edit") end end end @@ -131,6 +135,7 @@ RSpec.describe ArticlesController, type: :controller do it "redirects correctly" do login_admin + request.env["HTTP_REFERER"] = "where_i_came_from" delete :destroy, params: {:id => article.id} expect(response).to redirect_to("where_i_came_from")