mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
Update article spec
This commit is contained in:
parent
4c5108bc4e
commit
b1b39e42a8
1 changed files with 11 additions and 6 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue