Last active
May 1, 2017 07:57
-
-
Save unixc3t/3b69f6df9f900b3ba46e19bd0c9373b3 to your computer and use it in GitHub Desktop.
rspec code snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test get / | |
it 'get index' do | |
expect(get: "/").to route_to(controller: "links", | |
action: "index") | |
end | |
it 'get the about page' do | |
get :about | |
p response | |
expect(response).to render_template("about") | |
end | |
# devise login and use login user | |
let(:user) do | |
create(:user) | |
end | |
let(:login) do | |
@request.env["devise.mapping"] = Devise.mappings[:user] | |
sign_in user | |
end | |
it 'locates the requested @link' do | |
login | |
get :edit, id: link | |
expect(assigns(:link)).to eq link | |
expect(assigns(:link).user_id).to eq user.id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :user do | |
email {FFaker::Internet.email} | |
password '123456' | |
password_confirmation '123456' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it 'request upvote the link' do
login
request.env["HTTP_REFERER"] = "where_i_came_from"
patch :upvote, id: link
expect(assigns(:link).get_upvotes[0].vote_weight).to eq 1
expect(assigns(:link).get_upvotes[0].voter_id).to eq user.id