Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from nashikotokyo/feature/16_system_spec
Feature/16 system spec
- Loading branch information
Showing
12 changed files
with
299 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
= link_to likes_path(post_id: post.id), method: :post, remote: true do | ||
= link_to likes_path(post_id: post.id), class: 'like-button', method: :post, remote: true do | ||
= icon 'far', 'heart', class: 'fa-lg' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
= link_to like_path(current_user.likes.find_by(post_id: post.id)), method: :delete, remote: true do | ||
= link_to like_path(current_user.likes.find_by(post_id: post.id)), method: :delete, class: 'unlike-button', remote: true do | ||
= icon 'fa', 'heart', class: 'fa-lg' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module SystemHelper | ||
def login | ||
user = create(:user) | ||
visit login_path | ||
fill_in 'メールアドレス', with: user.email | ||
fill_in 'パスワード', with: '12345678' | ||
click_button 'ログイン' | ||
end | ||
|
||
def login_as(user) | ||
visit login_path | ||
fill_in 'メールアドレス', with: user.email | ||
fill_in 'パスワード', with: '12345678' | ||
click_button 'ログイン' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'ポスト', type: :system do | ||
|
||
describe 'ポスト一覧' do | ||
let!(:user) { create(:user) } | ||
let!(:post_1_by_others) { create(:post) } | ||
let!(:post_2_by_others) { create(:post) } | ||
let!(:post_by_user) { create(:post, user: user) } | ||
|
||
context 'ログインしている場合' do | ||
before do | ||
login_as user | ||
user.follow(post_1_by_others.user) | ||
end | ||
it 'フォロワーと自分の投稿だけが表示されること' do | ||
visit posts_path | ||
expect(page).to have_content post_1_by_others.body | ||
expect(page).to have_content post_by_user.body | ||
expect(page).not_to have_content post_2_by_others.body | ||
end | ||
end | ||
|
||
context 'ログインしていない場合' do | ||
it '全てのポストが表示されること' do | ||
visit posts_path | ||
expect(page).to have_content post_1_by_others.body | ||
expect(page).to have_content post_2_by_others.body | ||
expect(page).to have_content post_by_user.body | ||
end | ||
end | ||
end | ||
|
||
describe 'ポスト投稿' do | ||
it '画像を投稿できること' do | ||
login | ||
visit new_post_path | ||
within '#posts_form' do | ||
attach_file '画像', Rails.root.join('spec', 'fixtures', 'fixture.png') | ||
fill_in '本文', with: 'This is an example post' | ||
click_button '登録する' | ||
end | ||
|
||
expect(page).to have_content '投稿しました' | ||
expect(page).to have_content 'This is an example post' | ||
end | ||
end | ||
|
||
describe 'ポスト更新' do | ||
let!(:user) { create(:user) } | ||
let!(:post_1_by_others) { create(:post) } | ||
let!(:post_by_user) { create(:post, user: user) } | ||
before do | ||
login_as user | ||
end | ||
it '自分の投稿に編集ボタンが表示されること' do | ||
visit posts_path | ||
within "#post-#{post_by_user.id}" do | ||
expect(page).to have_css '.delete-button' | ||
expect(page).to have_css '.edit-button' | ||
end | ||
end | ||
|
||
it '他人の投稿には編集ボタンが表示されないこと' do | ||
user.follow(post_1_by_others.user) | ||
visit posts_path | ||
within "#post-#{post_1_by_others.id}" do | ||
expect(page).not_to have_css '.edit-button' | ||
end | ||
end | ||
|
||
it '投稿が更新できること' do | ||
visit edit_post_path(post_by_user) | ||
within '#posts_form' do | ||
attach_file '画像', Rails.root.join('spec', 'fixtures', 'fixture.png') | ||
fill_in '本文', with: 'This is an example updated post' | ||
click_button '更新する' | ||
end | ||
expect(page).to have_content '投稿を更新しました' | ||
expect(page).to have_content 'This is an example updated post' | ||
end | ||
end | ||
|
||
describe 'ポスト削除' do | ||
let!(:user) { create(:user) } | ||
let!(:post_1_by_others) { create(:post) } | ||
let!(:post_by_user) { create(:post, user: user) } | ||
before do | ||
login_as user | ||
end | ||
it '自分の投稿に削除ボタンが表示されること' do | ||
visit posts_path | ||
within "#post-#{post_by_user.id}" do | ||
expect(page).to have_css '.delete-button' | ||
end | ||
end | ||
|
||
it '他人の投稿には削除ボタンが表示されないこと' do | ||
user.follow(post_1_by_others.user) | ||
visit posts_path | ||
within "#post-#{post_1_by_others.id}" do | ||
expect(page).not_to have_css '.delete-button' | ||
end | ||
end | ||
|
||
it '投稿が削除できること' do | ||
visit posts_path | ||
within "#post-#{post_by_user.id}" do | ||
page.accept_confirm { find('.delete-button').click } | ||
end | ||
expect(page).to have_content '投稿を削除しました' | ||
expect(page).not_to have_content post_by_user.body | ||
end | ||
end | ||
|
||
describe 'ポスト詳細' do | ||
let(:user) { create(:user) } | ||
let(:post_by_user) { create(:post, user: user) } | ||
|
||
before do | ||
login_as user | ||
end | ||
|
||
it '投稿の詳細画面が閲覧できること' do | ||
visit post_path(post_by_user) | ||
expect(current_path).to eq post_path(post_by_user) | ||
end | ||
end | ||
|
||
describe 'いいね' do | ||
let!(:user) { create(:user) } | ||
let!(:post) { create(:post) } | ||
before do | ||
login_as user | ||
user.follow(post.user) | ||
end | ||
it 'いいねができること' do | ||
visit posts_path | ||
expect { | ||
within "#post-#{post.id}" do | ||
find('.like-button').click | ||
expect(page).to have_css '.unlike-button' | ||
end | ||
}.to change{user.like_posts.count}.by(1) | ||
end | ||
|
||
it 'いいねを取り消せること' do | ||
user.like(post) | ||
visit posts_path | ||
expect { | ||
within "#post-#{post.id}" do | ||
find('.unlike-button').click | ||
expect(page).to have_css '.like-button' | ||
end | ||
}.to change {user.like_posts.count}.by(-1) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'ログイン・ログアウト', type: :system do | ||
let(:user) { create(:user) } | ||
|
||
describe 'ログイン' do | ||
context '認証情報が正しい場合' do | ||
it 'ログインできること' do | ||
visit login_path | ||
fill_in 'メールアドレス', with: user.email | ||
fill_in 'パスワード', with: '12345678' | ||
click_button 'ログイン' | ||
expect(current_path).to eq posts_path | ||
expect(page).to have_content 'ログインしました' | ||
end | ||
end | ||
|
||
context '認証情報に誤りがある場合' do | ||
it 'ログインできないこと' do | ||
visit login_path | ||
fill_in 'メールアドレス', with: user.email | ||
fill_in 'パスワード', with: '1234' | ||
click_button 'ログイン' | ||
expect(current_path).to eq login_path | ||
expect(page).to have_content 'ログインに失敗しました' | ||
end | ||
end | ||
end | ||
|
||
describe 'ログアウト' do | ||
before do | ||
login | ||
end | ||
it 'ログアウトできること' do | ||
click_on('ログアウト') | ||
expect(current_path).to eq login_path | ||
expect(page).to have_content 'ログアウトしました' | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.
急なリダイレクト先の変更にびっくりしましたが、了解です笑