Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
Permalink
Browse files

update hash syntax in specs

  • Loading branch information
xuanxu committed Aug 20, 2019
1 parent 59d2a00 commit 093c326424003db66bd6feaddcb4161488df0129
@@ -17,7 +17,7 @@
<div class="navbar-nav ml-auto">

<%- if current_user&.admin? %>
<%= link_to "Editors", editors_path,class: "nav-item nav-link" %>
<%= link_to "Editors", editors_path, class: "nav-item nav-link" %>
<%- end %>

<%- if current_user&.editor %>

Large diffs are not rendered by default.

@@ -39,7 +39,7 @@
describe "#show" do
it "assigns the requested editor as @editor" do
editor = create(:editor)
get :show, params: {:id => editor.to_param}
get :show, params: {id: editor.to_param}
expect(assigns(:editor)).to eq(editor)
end
end
@@ -54,7 +54,7 @@
describe "#edit" do
it "assigns the requested editor as @editor" do
editor = create(:editor)
get :edit, params: {:id => editor.to_param}
get :edit, params: {id: editor.to_param}
expect(assigns(:editor)).to eq(editor)
end
end
@@ -63,30 +63,30 @@
context "with valid params" do
it "creates a new Editor" do
expect {
post :create, params: {:editor => build(:editor).attributes}
post :create, params: {editor: build(:editor).attributes}
}.to change(Editor, :count).by(1)
end

it "assigns a newly created editor as @editor" do
post :create, params: {:editor => build(:editor).attributes}
post :create, params: {editor: build(:editor).attributes}
expect(assigns(:editor)).to be_a(Editor)
expect(assigns(:editor)).to be_persisted
end

it "redirects to the created editor" do
post :create, params: {:editor => build(:editor).attributes}
post :create, params: {editor: build(:editor).attributes}
expect(response).to redirect_to(Editor.last)
end
end

context "with invalid params" do
it "assigns a newly created but unsaved editor as @editor" do
post :create, params: {:editor => {login: nil}}
post :create, params: {editor: {login: nil}}
expect(assigns(:editor)).to be_a_new(Editor)
end

it "re-renders the 'new' template" do
post :create, params: {:editor => {login: nil}}
post :create, params: {editor: {login: nil}}
expect(response).to render_template("new")
end
end
@@ -96,34 +96,34 @@
context "with valid params" do
it "updates the requested editor" do
editor = create(:editor)
put :update, params: {:id => editor.to_param, :editor => {first_name: "Different"}}
put :update, params: {id: editor.to_param, editor: {first_name: "Different"}}
editor.reload
expect(editor.first_name).to eql("Different")
end

it "assigns the requested editor as @editor" do
editor = create(:editor)
put :update, params: {:id => editor.to_param, :editor => {first_name: "Different"}}
put :update, params: {id: editor.to_param, editor: {first_name: "Different"}}
expect(assigns(:editor)).to eq(editor)
end

it "redirects to the editor" do
editor = create(:editor)
put :update, params: {:id => editor.to_param, :editor => {first_name: "Different"}}
put :update, params: {id: editor.to_param, editor: {first_name: "Different"}}
expect(response).to redirect_to(editor)
end
end

context "with invalid params" do
it "assigns the editor as @editor" do
editor = create(:editor)
put :update, params: {:id => editor.to_param, :editor => {login: nil}}
put :update, params: {id: editor.to_param, editor: {login: nil}}
expect(assigns(:editor)).to eq(editor)
end

it "re-renders the 'edit' template" do
editor = create(:editor)
put :update, params: {:id => editor.to_param, :editor => {login: nil}}
put :update, params: {id: editor.to_param, editor: {login: nil}}
expect(response).to render_template("edit")
end
end
@@ -133,13 +133,13 @@
it "destroys the requested editor" do
editor = create(:editor)
expect {
delete :destroy, params: {:id => editor.to_param}
delete :destroy, params: {id: editor.to_param}
}.to change(Editor, :count).by(-1)
end

it "redirects to the editors list" do
editor = create(:editor)
delete :destroy, params: {:id => editor.to_param}
delete :destroy, params: {id: editor.to_param}
expect(response).to redirect_to(editors_url)
end
end
@@ -1,76 +1,76 @@
require 'rails_helper'

describe HomeController, :type => :controller do
describe HomeController, type: :controller do
render_views

describe "GET #index" do
it "should render home page" do
get :index, :format => :html
get :index, format: :html
expect(response).to be_successful
expect(response.body).to match /The Journal of Open Source Software/
end
end

describe "LOGGED IN GET #index" do
it "should render home page and ask for our email if we don't have one" do
user = create(:user, :email => nil)
user = create(:user, email: nil)
allow(controller).to receive_message_chain(:current_user).and_return(user)

get :index, :format => :html
get :index, format: :html
expect(response).to be_successful
expect(response.body).to match /you need to add your email address and GitHub handle/
end

it "should render home page and ask for a profile update if we don't have a github username" do
user = create(:user, :email => 'arfon@example.com', :github_username => nil)
user = create(:user, email: 'arfon@example.com', github_username: nil)
allow(controller).to receive_message_chain(:current_user).and_return(user)

get :index, :format => :html
get :index, format: :html
expect(response).to be_successful
expect(response.body).to match /you need to add your email address and GitHub handle/
end
end

describe "GET #about" do
it "should render about page" do
get :about, :format => :html
get :about, format: :html
expect(response).to be_successful
expect(response.body).to match /Don't we have enough journals already?/
end
end

describe "GET #profile" do
it "should render profile page without 'update my profile banner'" do
user = create(:user, :email => nil, :github_username => nil)
user = create(:user, email: nil, github_username: nil)
allow(controller).to receive_message_chain(:current_user).and_return(user)

# FIXME: Fix this test
# get :profile, :format => :html
# get :profile, format: :html
# expect(response).to be_successful
# expect(response.body).not_to match /Please update your profile before continuing/
end
end

describe "POST #update_profile" do
it "should update their email address" do
user = create(:user, :email => nil, :github_username => nil)
user = create(:user, email: nil, github_username: nil)
allow(controller).to receive_message_chain(:current_user).and_return(user)
params = {:email => "albert@gmail.com", :github_username => "@jimmy"}
params = {email: "albert@gmail.com", github_username: "@jimmy"}
request.env["HTTP_REFERER"] = papers_path

post :update_profile, params: {:user => params}
post :update_profile, params: {user: params}
expect(response).to be_redirect # as it's updated the email
expect(user.reload.email).to eq("albert@gmail.com")
expect(user.reload.github_username).to eq("@jimmy")
end

it "should add an @ to their GitHub username if they don't use one" do
user = create(:user, :email => nil, :github_username => nil)
user = create(:user, email: nil, github_username: nil)
allow(controller).to receive_message_chain(:current_user).and_return(user)
params = {:email => "albert@gmail.com", :github_username => "jimmy_no_at"}
params = {email: "albert@gmail.com", github_username: "jimmy_no_at"}
request.env["HTTP_REFERER"] = papers_path

post :update_profile, params: {:user => params}
post :update_profile, params: {user: params}
expect(response).to be_redirect # as it's updated the email
expect(user.reload.email).to eq("albert@gmail.com")
expect(user.reload.github_username).to eq("@jimmy_no_at")

0 comments on commit 093c326

Please sign in to comment.
You can’t perform that action at this time.