From 12b3ba179cbccb1258c4ade32e352cf2d7c48885 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 8 Oct 2019 13:24:24 +0900 Subject: [PATCH 01/28] =?UTF-8?q?Feature:=20vendor/bundle=E3=82=92git=20ig?= =?UTF-8?q?nore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8a4846120..6bfe6e990 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ /public/assets .byebug_history +/vendor/bundle # Ignore master key for decrypting credentials and more. /config/master.key From 0368f162702ddc43cea8fd2a8a88f8faecf67795 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 8 Oct 2019 13:25:10 +0900 Subject: [PATCH 02/28] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E9=80=94?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rspec | 1 + Gemfile | 4 ++ Gemfile.lock | 50 +++++++++++++++++++++ spec/factories/task.rb | 8 ++++ spec/factories/user.rb | 7 +++ spec/rails_helper.rb | 62 ++++++++++++++++++++++++++ spec/spec_helper.rb | 96 ++++++++++++++++++++++++++++++++++++++++ spec/system/task_spec.rb | 40 +++++++++++++++++ spec/system/user_spec.rb | 43 ++++++++++++++++++ 9 files changed, 311 insertions(+) create mode 100644 .rspec create mode 100644 spec/factories/task.rb create mode 100644 spec/factories/user.rb create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/system/task_spec.rb create mode 100644 spec/system/user_spec.rb diff --git a/.rspec b/.rspec new file mode 100644 index 000000000..c99d2e739 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Gemfile b/Gemfile index 2565a74b0..7f2750944 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,10 @@ gem 'sorcery' group :development, :test do gem 'byebug', platforms: %i[mri mingw x64_mingw] + gem 'rspec-rails' + gem 'capybara' + gem 'webdrivers' + gem 'factory_bot_rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 708d867c8..2bcd96a9e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,8 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) ast (2.4.0) bcrypt (3.1.13) @@ -56,6 +58,15 @@ GEM msgpack (~> 1.0) builder (3.2.3) byebug (11.0.1) + capybara (3.29.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + childprocess (3.0.0) code_analyzer (0.4.8) sexp_processor coderay (1.1.2) @@ -69,9 +80,15 @@ GEM concurrent-ruby (1.1.5) crass (1.0.4) debug_inspector (0.0.3) + diff-lcs (1.3) erubi (1.9.0) erubis (2.7.0) execjs (2.7.0) + factory_bot (5.1.1) + activesupport (>= 4.2.0) + factory_bot_rails (5.1.1) + factory_bot (~> 5.1.0) + railties (>= 4.2.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) ffi (1.11.1) @@ -126,6 +143,7 @@ GEM yard (~> 0.9.11) pry-rails (0.3.9) pry (>= 0.10.4) + public_suffix (4.0.1) puma (3.12.1) rack (2.0.7) rack-test (1.1.0) @@ -167,7 +185,25 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) + regexp_parser (1.6.0) require_all (2.0.0) + rspec-core (3.8.2) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-rails (3.8.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.3) rubocop (0.74.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -177,6 +213,7 @@ GEM unicode-display_width (>= 1.4.0, < 1.7) ruby-progressbar (1.10.1) ruby_dep (1.5.0) + rubyzip (1.3.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -188,6 +225,9 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + selenium-webdriver (3.142.6) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) sexp_processor (4.13.0) sorcery (0.14.0) bcrypt (~> 3.1) @@ -218,9 +258,15 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) + webdrivers (4.1.2) + nokogiri (~> 1.6) + rubyzip (~> 1.0) + selenium-webdriver (>= 3.0, < 4.0) websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.4) + xpath (3.2.0) + nokogiri (~> 1.8) yard (0.9.20) PLATFORMS @@ -231,7 +277,9 @@ DEPENDENCIES binding_of_caller bootsnap (>= 1.1.0) byebug + capybara coffee-rails (~> 4.2) + factory_bot_rails listen (>= 3.0.5, < 3.2) pry-byebug pry-doc @@ -239,6 +287,7 @@ DEPENDENCIES puma (~> 3.11) rails (~> 5.2.3) rails_best_practices + rspec-rails rubocop sass-rails (~> 5.0) sorcery @@ -248,6 +297,7 @@ DEPENDENCIES tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) + webdrivers RUBY VERSION ruby 2.6.4p104 diff --git a/spec/factories/task.rb b/spec/factories/task.rb new file mode 100644 index 000000000..e96ed32b0 --- /dev/null +++ b/spec/factories/task.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :task do + title { "title" } + content { "content" } + status { 0 } + deadline { '2019/10/9 11:11' } + end +end diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 000000000..98fcc1d2e --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :user do + email { "example@gmail.com" } + password { "password" } + password_confirmation { "password" } + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 000000000..8d56f4c4e --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,62 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 000000000..ce33d66df --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,96 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb new file mode 100644 index 000000000..ced8f8078 --- /dev/null +++ b/spec/system/task_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +RSpec.describe 'Users', type: :system do + describe 'タスクの新規作成、編集、削除' do + context '正常系' do + let!(:user) { create(:user) } + let!(:task) { build(:task) } + let(:task_created) { create(:task) } + # login + before do + visit login_path + fill_in 'email', with: user.email + fill_in 'password', with: 'password' + click_button 'Login' + end + it 'ログインした状態でタスクの新規作成' do + visit new_task_path + fill_in 'task_title', with: task.title + fill_in 'task_content', with: task.content + select task.status, from: 'task_status' + fill_in 'task_deadline', with: task.deadline + click_button 'Create Task' + expect(page).to have_content 'Task was successfully created.' + end + it 'ログインした状態でタスクの編集' do + visit edit_task_path(task_created) + fill_in 'task_title', with: 'title updated' + click_button 'Update Task' + expect(page).to have_content 'Task was successfully updated.' + end + it 'ログインした状態でタスクの削除' do + expect { + delete task_path(task_created), params: { id: task_created.id } + }.to change(Task, :count).by(-1) + end + end + end + describe 'タスクの表示' do + end +end diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb new file mode 100644 index 000000000..cadd4701a --- /dev/null +++ b/spec/system/user_spec.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +RSpec.describe 'Users', type: :system do + describe 'ログイン' do + context '正常系' do + let!(:user) { create(:user) } + it 'ログインが成功すること' do + visit login_path + fill_in 'email', with: user.email + fill_in 'password', with: 'password' + click_button 'Login' + expect(page).to have_content 'Login successful' + end + end + context '異常系' do + it '未入力時にログインが失敗すること' do + visit login_path + click_button 'Login' + expect(page).to have_content 'Login failed' + end + end + end + describe 'サインアップ' do + context '正常系' do + let!(:user) { build(:user) } + it 'ユーザーの新規作成、編集、削除ができること' do + visit sign_up_path + fill_in 'user_email', with: user.email + fill_in 'user_password', with: user.password + fill_in 'user_password_confirmation', with: user.password_confirmation + click_button 'SignUp' + expect(page).to have_content 'User was successfully created.' + end + end + context '異常系' do + it '未入力時にユーザーの新規作成が失敗すること' do + visit sign_up_path + click_button 'SignUp' + expect(page).to have_content 'error' + end + end + end +end From 5cdccb6bc3abdfe87f22b60f7ac4aa8fbbb15f24 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 8 Oct 2019 18:27:29 +0900 Subject: [PATCH 03/28] Feature: user, task system spec --- spec/support/utilities.rb | 6 ++++ spec/system/task_spec.rb | 63 +++++++++++++++++++++++++++++++-------- spec/system/user_spec.rb | 9 ++---- 3 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 spec/support/utilities.rb diff --git a/spec/support/utilities.rb b/spec/support/utilities.rb new file mode 100644 index 000000000..e6752eaef --- /dev/null +++ b/spec/support/utilities.rb @@ -0,0 +1,6 @@ +def login_as(user) + visit login_path + fill_in 'email', with: user.email + fill_in 'password', with: 'password' + click_button 'Login' +end diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index ced8f8078..bdeeaff07 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -3,17 +3,14 @@ RSpec.describe 'Users', type: :system do describe 'タスクの新規作成、編集、削除' do context '正常系' do - let!(:user) { create(:user) } - let!(:task) { build(:task) } - let(:task_created) { create(:task) } + let(:user) { create(:user) } + let(:task) { build(:task, title: 'task_new') } + let!(:task_created){ create(:task, :user_id => user.id) } # login before do - visit login_path - fill_in 'email', with: user.email - fill_in 'password', with: 'password' - click_button 'Login' + login_as(user) end - it 'ログインした状態でタスクの新規作成' do + it 'ログインした状態でタスクの新規作成できる' do visit new_task_path fill_in 'task_title', with: task.title fill_in 'task_content', with: task.content @@ -22,19 +19,59 @@ click_button 'Create Task' expect(page).to have_content 'Task was successfully created.' end - it 'ログインした状態でタスクの編集' do + it 'ログインした状態でタスクの編集できる' do visit edit_task_path(task_created) fill_in 'task_title', with: 'title updated' click_button 'Update Task' expect(page).to have_content 'Task was successfully updated.' end - it 'ログインした状態でタスクの削除' do - expect { - delete task_path(task_created), params: { id: task_created.id } - }.to change(Task, :count).by(-1) + it 'ログインした状態でタスクの削除できる' do + visit tasks_path + click_on 'Destroy' + page.driver.browser.switch_to.alert.accept + expect(page).to have_content 'Task was successfully destroyed.' + end + end + context '異常系' do + let(:user) { create(:user) } + let(:task) { build(:task) } + let!(:task_created){ create(:task, :user_id => user.id) } + it 'ログインしていない状態でタスクの新規作成に遷移できない' do + visit new_task_path + expect(page).to have_content 'Login required' + end + it 'ログインしていない状態でタスクの編集に遷移できない' do + visit edit_task_path(task_created) + expect(page).to have_content 'Login required' + end + it 'ログインしていない状態でタスクのマイページに遷移できない' do + visit user_path(user) + expect(page).to have_content 'Login required' end end end describe 'タスクの表示' do + let(:user) { create(:user) } + let(:user_another) { create(:user, email: 'another@gmail.com') } + let!(:task){ create(:task, :user_id => user.id) } + # login + before do + login_as(user) + end + context '正常系' do + it 'マイページにユーザーが新規作成したタスクが表示されること' do + visit user_path(user) + expect(page).to have_content task.title + expect(page).to have_content task.status + end + end + before do + login_as(user_another) + end + context '異常系' do + it 'マイページにユーザーが新規作成したタスクが表示されること' do + visit edit_task_path(task_created) + end + end end end diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index cadd4701a..b4ba85f99 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -3,12 +3,9 @@ RSpec.describe 'Users', type: :system do describe 'ログイン' do context '正常系' do - let!(:user) { create(:user) } + let(:user) { create(:user) } it 'ログインが成功すること' do - visit login_path - fill_in 'email', with: user.email - fill_in 'password', with: 'password' - click_button 'Login' + login_as(user) expect(page).to have_content 'Login successful' end end @@ -22,7 +19,7 @@ end describe 'サインアップ' do context '正常系' do - let!(:user) { build(:user) } + let(:user) { build(:user) } it 'ユーザーの新規作成、編集、削除ができること' do visit sign_up_path fill_in 'user_email', with: user.email From ab8c137df317e6cefdac039ab81aefbfee193158 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 8 Oct 2019 18:53:15 +0900 Subject: [PATCH 04/28] =?UTF-8?q?Feature:=20=E5=88=A5=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E3=81=8C=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E9=96=B2=E8=A6=A7=E3=81=97=E3=81=9F=E6=99=82=E3=81=AE=E7=95=B0?= =?UTF-8?q?=E5=B8=B8=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index bdeeaff07..cd88b3fb3 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -35,7 +35,7 @@ context '異常系' do let(:user) { create(:user) } let(:task) { build(:task) } - let!(:task_created){ create(:task, :user_id => user.id) } + let!(:task_created){ create(:task, user_id: user.id) } it 'ログインしていない状態でタスクの新規作成に遷移できない' do visit new_task_path expect(page).to have_content 'Login required' @@ -55,22 +55,19 @@ let(:user_another) { create(:user, email: 'another@gmail.com') } let!(:task){ create(:task, :user_id => user.id) } # login - before do - login_as(user) - end context '正常系' do it 'マイページにユーザーが新規作成したタスクが表示されること' do + login_as(user) visit user_path(user) expect(page).to have_content task.title expect(page).to have_content task.status end end - before do - login_as(user_another) - end context '異常系' do it 'マイページにユーザーが新規作成したタスクが表示されること' do - visit edit_task_path(task_created) + login_as(user_another) + visit edit_task_path(task) + expect(page).to have_content 'Forbidden access.' end end end From 32ee76e748b9c50bf23909539b7247eabcef346f Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 11:41:29 +0900 Subject: [PATCH 05/28] Fix: rocket hash --- spec/system/task_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index cd88b3fb3..54351c77e 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -5,7 +5,7 @@ context '正常系' do let(:user) { create(:user) } let(:task) { build(:task, title: 'task_new') } - let!(:task_created){ create(:task, :user_id => user.id) } + let!(:task_created){ create(:task, user_id: user.id) } # login before do login_as(user) @@ -53,7 +53,7 @@ describe 'タスクの表示' do let(:user) { create(:user) } let(:user_another) { create(:user, email: 'another@gmail.com') } - let!(:task){ create(:task, :user_id => user.id) } + let!(:task){ create(:task, user_id: user.id) } # login context '正常系' do it 'マイページにユーザーが新規作成したタスクが表示されること' do From 3da662dec8a7e0c6e595e65d9cc7292224bdb345 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 11:42:44 +0900 Subject: [PATCH 06/28] =?UTF-8?q?Fix:=20=E7=95=B0=E5=B8=B8=E7=B3=BB?= =?UTF-8?q?=E3=81=AE=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=81=AE=E4=B8=80?= =?UTF-8?q?=E3=81=A4=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 54351c77e..5e1088dfe 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -64,7 +64,7 @@ end end context '異常系' do - it 'マイページにユーザーが新規作成したタスクが表示されること' do + it '他のユーザーのタスク編集ページへの遷移ができないこと' do login_as(user_another) visit edit_task_path(task) expect(page).to have_content 'Forbidden access.' From 41293f3e5c2fae6bb4ffc8fa01f3f7412cf40987 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 11:46:49 +0900 Subject: [PATCH 07/28] =?UTF-8?q?Fix:=20update=E6=99=82=E3=80=81=E7=B7=A8?= =?UTF-8?q?=E9=9B=86=E3=81=97=E3=81=9F=E5=86=85=E5=AE=B9=E3=81=AE=E9=A0=85?= =?UTF-8?q?=E7=9B=AE=E3=81=8C=E7=94=BB=E9=9D=A2=E4=B8=8A=E3=81=AB=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=81=95=E3=82=8C=E3=82=8B=E3=81=93=E3=81=A8=E3=82=92?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 5e1088dfe..5c00549a4 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -21,9 +21,10 @@ end it 'ログインした状態でタスクの編集できる' do visit edit_task_path(task_created) - fill_in 'task_title', with: 'title updated' + fill_in 'task_title', with: 'title_updated' click_button 'Update Task' expect(page).to have_content 'Task was successfully updated.' + expect(page).to have_content 'title_updated' end it 'ログインした状態でタスクの削除できる' do visit tasks_path From ccd261749e7b75147e6b96e9d4ab53c9370f2e17 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 11:57:01 +0900 Subject: [PATCH 08/28] =?UTF-8?q?Fix:=20delete=E6=99=82=E3=80=81=E8=A9=B2?= =?UTF-8?q?=E5=BD=93=E3=83=AC=E3=82=B3=E3=83=BC=E3=83=89=E3=81=8C=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E3=81=97=E3=81=AA=E3=81=84=E3=81=93=E3=81=A8=E3=82=92?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 5c00549a4..1759c38dc 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -31,6 +31,7 @@ click_on 'Destroy' page.driver.browser.switch_to.alert.accept expect(page).to have_content 'Task was successfully destroyed.' + expect{Task.find(task_created.id)}.to raise_exception(ActiveRecord::RecordNotFound) end end context '異常系' do From 11763b9c8e22fe673d3d5d8ebef24cd4d047d4d4 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 12:20:33 +0900 Subject: [PATCH 09/28] =?UTF-8?q?Feature:=20user=20update=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index b4ba85f99..75cc1ffb8 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -20,7 +20,8 @@ describe 'サインアップ' do context '正常系' do let(:user) { build(:user) } - it 'ユーザーの新規作成、編集、削除ができること' do + let(:user_created) { create(:user) } + it 'ユーザーの新規作成ができること' do visit sign_up_path fill_in 'user_email', with: user.email fill_in 'user_password', with: user.password @@ -28,6 +29,16 @@ click_button 'SignUp' expect(page).to have_content 'User was successfully created.' end + it 'ユーザーの編集ができること' do + login_as(user_created) + visit edit_user_path(user_created) + fill_in 'user_email', with: 'updated@gmail.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' + click_button 'SignUp' + expect(page).to have_content 'User was successfully updated.' + expect(page).to have_content 'updated@gmail.com' + end end context '異常系' do it '未入力時にユーザーの新規作成が失敗すること' do From 5e68254673dad6e1666ceeb698149983ce1df6c2 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 12:32:37 +0900 Subject: [PATCH 10/28] =?UTF-8?q?Fix:=20task=20new=E6=99=82=E3=80=81index?= =?UTF-8?q?=E3=81=AB=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C=E3=82=8B=E3=81=93?= =?UTF-8?q?=E3=81=A8=E3=82=92=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 1759c38dc..d8c9f30b3 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -18,6 +18,10 @@ fill_in 'task_deadline', with: task.deadline click_button 'Create Task' expect(page).to have_content 'Task was successfully created.' + visit tasks_path + expect(page).to have_content task.content + expect(page).to have_content task.status + expect(page).to have_content task.deadline.strftime('%Y/%-m/%-d %-H:%-M') end it 'ログインした状態でタスクの編集できる' do visit edit_task_path(task_created) From 55e477e67136ba85563c5296eb4d803be03fc085 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 12:33:58 +0900 Subject: [PATCH 11/28] =?UTF-8?q?Fix:=20task=5Fspec=E3=81=AE=E6=9C=80?= =?UTF-8?q?=E5=88=9D=E3=81=AE=E3=82=AD=E3=83=A3=E3=83=97=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=81=AE=E3=83=9F=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index d8c9f30b3..d16246f45 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Users', type: :system do +RSpec.describe 'Tasks', type: :system do describe 'タスクの新規作成、編集、削除' do context '正常系' do let(:user) { create(:user) } From dad025a99b7afba9b7c792ba6a8c663142660479 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 14:23:15 +0900 Subject: [PATCH 12/28] =?UTF-8?q?Fix:=20login=E3=81=AB=E3=83=AA=E3=83=80?= =?UTF-8?q?=E3=82=A4=E3=83=AC=E3=82=AF=E3=83=88=E3=81=97=E3=81=9F=E6=99=82?= =?UTF-8?q?=E3=80=81current=5Fpath=E3=81=AE=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index d16246f45..228270b4e 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -45,14 +45,17 @@ it 'ログインしていない状態でタスクの新規作成に遷移できない' do visit new_task_path expect(page).to have_content 'Login required' + expect(current_path).to eq '/login' end it 'ログインしていない状態でタスクの編集に遷移できない' do visit edit_task_path(task_created) expect(page).to have_content 'Login required' + expect(current_path).to eq '/login' end it 'ログインしていない状態でタスクのマイページに遷移できない' do visit user_path(user) expect(page).to have_content 'Login required' + expect(current_path).to eq '/login' end end end From a83845b5042cae5058c7186e318b221230a938af Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 15:05:48 +0900 Subject: [PATCH 13/28] =?UTF-8?q?Fix:=20task=E3=81=AEcreate=E3=81=A7let!?= =?UTF-8?q?=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8Flet=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 228270b4e..7e1be367a 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -5,7 +5,7 @@ context '正常系' do let(:user) { create(:user) } let(:task) { build(:task, title: 'task_new') } - let!(:task_created){ create(:task, user_id: user.id) } + let(:task_created){ create(:task, user_id: user.id) } # login before do login_as(user) @@ -31,6 +31,7 @@ expect(page).to have_content 'title_updated' end it 'ログインした状態でタスクの削除できる' do + task_created visit tasks_path click_on 'Destroy' page.driver.browser.switch_to.alert.accept From 188182cfd4b835b4b6501d8cea7282b912f69670 Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 15:21:09 +0900 Subject: [PATCH 14/28] =?UTF-8?q?Fix:=20path=E3=82=92login=5Fpath=E3=81=A8?= =?UTF-8?q?=E8=A8=98=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 7e1be367a..23ead036b 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -46,17 +46,17 @@ it 'ログインしていない状態でタスクの新規作成に遷移できない' do visit new_task_path expect(page).to have_content 'Login required' - expect(current_path).to eq '/login' + expect(current_path).to eq login_path end it 'ログインしていない状態でタスクの編集に遷移できない' do visit edit_task_path(task_created) expect(page).to have_content 'Login required' - expect(current_path).to eq '/login' + expect(current_path).to eq login_path end it 'ログインしていない状態でタスクのマイページに遷移できない' do visit user_path(user) expect(page).to have_content 'Login required' - expect(current_path).to eq '/login' + expect(current_path).to eq login_path end end end From 1abf20ae170e17f76521f6fe5e41c2bc26c51f9c Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 16:47:20 +0900 Subject: [PATCH 15/28] =?UTF-8?q?Fix:=20user=5Fspec=E3=81=AEdescribe,=20co?= =?UTF-8?q?ntext=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index 75cc1ffb8..2d450fef7 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -1,27 +1,26 @@ require 'rails_helper' RSpec.describe 'Users', type: :system do - describe 'ログイン' do - context '正常系' do + describe 'ログイン画面' do + context '入力値が正常な状態' do let(:user) { create(:user) } it 'ログインが成功すること' do login_as(user) expect(page).to have_content 'Login successful' end end - context '異常系' do - it '未入力時にログインが失敗すること' do + context '入力値が異常な状態' do + it 'ログインが失敗すること' do visit login_path click_button 'Login' expect(page).to have_content 'Login failed' end end end - describe 'サインアップ' do - context '正常系' do + describe 'サインアップ画面' do + context '入力値が正常な状態' do let(:user) { build(:user) } - let(:user_created) { create(:user) } - it 'ユーザーの新規作成ができること' do + it 'ユーザーの新規作成が成功すること' do visit sign_up_path fill_in 'user_email', with: user.email fill_in 'user_password', with: user.password @@ -29,9 +28,21 @@ click_button 'SignUp' expect(page).to have_content 'User was successfully created.' end + end + context '入力値が異常な状態' do + it 'ユーザーの新規作成が失敗すること' do + visit sign_up_path + click_button 'SignUp' + expect(page).to have_content 'error' + end + end + end + describe 'ユーザー編集画面' do + context '入力値が正常な状態' do + let(:user) { create(:user) } it 'ユーザーの編集ができること' do - login_as(user_created) - visit edit_user_path(user_created) + login_as(user) + visit edit_user_path(user) fill_in 'user_email', with: 'updated@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' @@ -40,9 +51,14 @@ expect(page).to have_content 'updated@gmail.com' end end - context '異常系' do - it '未入力時にユーザーの新規作成が失敗すること' do - visit sign_up_path + context '入力値が異常な状態' do + let(:user) { create(:user) } + it 'ユーザーの編集ができるないこと' do + login_as(user) + visit edit_user_path(user) + fill_in 'user_email', with: '' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' click_button 'SignUp' expect(page).to have_content 'error' end From 6f05688fba6fe5c03a5568899ae28dca682bd93d Mon Sep 17 00:00:00 2001 From: yusuke Date: Thu, 10 Oct 2019 18:46:06 +0900 Subject: [PATCH 16/28] =?UTF-8?q?Fix:=20describe,=20context=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 96 ++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index 23ead036b..da5e6ce08 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -1,16 +1,13 @@ require 'rails_helper' RSpec.describe 'Tasks', type: :system do - describe 'タスクの新規作成、編集、削除' do - context '正常系' do + describe 'タスクの新規作成画面' do + context 'ログインした状態' do let(:user) { create(:user) } let(:task) { build(:task, title: 'task_new') } let(:task_created){ create(:task, user_id: user.id) } - # login - before do + it 'タスクが新規作成できる' do login_as(user) - end - it 'ログインした状態でタスクの新規作成できる' do visit new_task_path fill_in 'task_title', with: task.title fill_in 'task_content', with: task.content @@ -23,14 +20,43 @@ expect(page).to have_content task.status expect(page).to have_content task.deadline.strftime('%Y/%-m/%-d %-H:%-M') end - it 'ログインした状態でタスクの編集できる' do + end + context 'ログインしていない状態' do + it 'タスクの新規作成に遷移できない' do + visit new_task_path + expect(page).to have_content 'Login required' + expect(current_path).to eq login_path + end + end + end + describe 'タスクの編集画面' do + context 'ログインした状態' do + let(:user) { create(:user) } + let(:task_created){ create(:task, user_id: user.id) } + it 'タスクが編集できる' do + login_as(user) visit edit_task_path(task_created) fill_in 'task_title', with: 'title_updated' click_button 'Update Task' expect(page).to have_content 'Task was successfully updated.' expect(page).to have_content 'title_updated' end - it 'ログインした状態でタスクの削除できる' do + end + context 'ログインしていない状態' do + let(:task_created){ create(:task) } + it 'タスクの編集に遷移できない' do + visit edit_task_path(task_created) + expect(page).to have_content 'Login required' + expect(current_path).to eq login_path + end + end + end + describe 'タスクの削除画面' do + context 'ログインした状態' do + let(:user) { create(:user) } + let(:task_created){ create(:task, user_id: user.id) } + it 'タスクが削除できる' do + login_as(user) task_created visit tasks_path click_on 'Destroy' @@ -39,42 +65,48 @@ expect{Task.find(task_created.id)}.to raise_exception(ActiveRecord::RecordNotFound) end end - context '異常系' do - let(:user) { create(:user) } - let(:task) { build(:task) } - let!(:task_created){ create(:task, user_id: user.id) } - it 'ログインしていない状態でタスクの新規作成に遷移できない' do - visit new_task_path - expect(page).to have_content 'Login required' - expect(current_path).to eq login_path + context 'ログインしていない状態' do + it 'タスクの削除に遷移できない' do + visit tasks_path + expect(page).not_to have_content 'Destroy' end - it 'ログインしていない状態でタスクの編集に遷移できない' do - visit edit_task_path(task_created) - expect(page).to have_content 'Login required' - expect(current_path).to eq login_path + end + end + describe 'タスクの詳細画面' do + context 'ログインした状態' do + let(:user) { create(:user) } + let(:task){ create(:task) } + it 'タスクの詳細に遷移できる' do + login_as(user) + visit task_path(task) + expect(page).to have_content task.title end - it 'ログインしていない状態でタスクのマイページに遷移できない' do - visit user_path(user) - expect(page).to have_content 'Login required' - expect(current_path).to eq login_path + end + context 'ログインしていない状態' do + let(:task){ create(:task) } + it 'タスクの詳細に遷移できる' do + visit task_path(task) + expect(page).to have_content task.title end end end - describe 'タスクの表示' do + describe 'タスクの詳細画面' do let(:user) { create(:user) } - let(:user_another) { create(:user, email: 'another@gmail.com') } - let!(:task){ create(:task, user_id: user.id) } - # login - context '正常系' do - it 'マイページにユーザーが新規作成したタスクが表示されること' do + let(:task){ create(:task, user_id: user.id) } + context 'ログインした状態' do + it 'マイページにユーザーが新規作成したタスクが表示される' do login_as(user) + task visit user_path(user) expect(page).to have_content task.title expect(page).to have_content task.status end end - context '異常系' do - it '他のユーザーのタスク編集ページへの遷移ができないこと' do + let(:user) { create(:user) } + let(:user_another) { create(:user, email: 'another@gmail.com') } + let(:task){ create(:task, user_id: user.id) } + context 'ログインしていない状態' do + it '他のユーザーのタスク編集ページへの遷移ができない' do login_as(user_another) visit edit_task_path(task) expect(page).to have_content 'Forbidden access.' From b6aad56cd914bf7fada1d68a0da780759001b2c3 Mon Sep 17 00:00:00 2001 From: yusuke Date: Fri, 11 Oct 2019 15:39:01 +0900 Subject: [PATCH 17/28] =?UTF-8?q?Fix:=20let=E3=82=92=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=81=AE=E4=B8=80=E7=95=AA?= =?UTF-8?q?=E4=B8=8A=E3=81=AB=E3=81=BE=E3=81=A8=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index 2d450fef7..db3ee7a99 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' RSpec.describe 'Users', type: :system do + let(:user) { create(:user) } describe 'ログイン画面' do context '入力値が正常な状態' do - let(:user) { create(:user) } it 'ログインが成功すること' do login_as(user) expect(page).to have_content 'Login successful' @@ -19,12 +19,11 @@ end describe 'サインアップ画面' do context '入力値が正常な状態' do - let(:user) { build(:user) } it 'ユーザーの新規作成が成功すること' do visit sign_up_path - fill_in 'user_email', with: user.email - fill_in 'user_password', with: user.password - fill_in 'user_password_confirmation', with: user.password_confirmation + fill_in 'user_email', with: 'example@gmail.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' click_button 'SignUp' expect(page).to have_content 'User was successfully created.' end @@ -39,7 +38,6 @@ end describe 'ユーザー編集画面' do context '入力値が正常な状態' do - let(:user) { create(:user) } it 'ユーザーの編集ができること' do login_as(user) visit edit_user_path(user) @@ -52,7 +50,6 @@ end end context '入力値が異常な状態' do - let(:user) { create(:user) } it 'ユーザーの編集ができるないこと' do login_as(user) visit edit_user_path(user) From 2c28e9356ed5548d3e38ef800acfb19e524dfd30 Mon Sep 17 00:00:00 2001 From: yusuke Date: Fri, 11 Oct 2019 15:39:30 +0900 Subject: [PATCH 18/28] =?UTF-8?q?Fix:=20let=E3=82=92=E3=81=BE=E3=81=A8?= =?UTF-8?q?=E3=82=81=E3=82=8B=E3=80=81task=20new=E3=81=A7let=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 41 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index da5e6ce08..de8131b9a 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -1,24 +1,24 @@ require 'rails_helper' RSpec.describe 'Tasks', type: :system do + let(:user) { create(:user) } + let(:user_another) { create(:user, email: 'another@gmail.com') } + let(:task){ create(:task, user_id: user.id) } describe 'タスクの新規作成画面' do context 'ログインした状態' do - let(:user) { create(:user) } - let(:task) { build(:task, title: 'task_new') } - let(:task_created){ create(:task, user_id: user.id) } it 'タスクが新規作成できる' do login_as(user) visit new_task_path - fill_in 'task_title', with: task.title - fill_in 'task_content', with: task.content - select task.status, from: 'task_status' - fill_in 'task_deadline', with: task.deadline + fill_in 'task_title', with: 'title' + fill_in 'task_content', with: 'content' + select 'todo', from: 'task_status' + fill_in 'task_deadline', with: '002019/10/9 11:11' click_button 'Create Task' expect(page).to have_content 'Task was successfully created.' visit tasks_path - expect(page).to have_content task.content - expect(page).to have_content task.status - expect(page).to have_content task.deadline.strftime('%Y/%-m/%-d %-H:%-M') + expect(page).to have_content 'content' + expect(page).to have_content 'todo' + expect(page).to have_content '2019/10/9 11:11' end end context 'ログインしていない状態' do @@ -31,11 +31,9 @@ end describe 'タスクの編集画面' do context 'ログインした状態' do - let(:user) { create(:user) } - let(:task_created){ create(:task, user_id: user.id) } it 'タスクが編集できる' do login_as(user) - visit edit_task_path(task_created) + visit edit_task_path(task) fill_in 'task_title', with: 'title_updated' click_button 'Update Task' expect(page).to have_content 'Task was successfully updated.' @@ -43,9 +41,8 @@ end end context 'ログインしていない状態' do - let(:task_created){ create(:task) } it 'タスクの編集に遷移できない' do - visit edit_task_path(task_created) + visit edit_task_path(task) expect(page).to have_content 'Login required' expect(current_path).to eq login_path end @@ -53,16 +50,14 @@ end describe 'タスクの削除画面' do context 'ログインした状態' do - let(:user) { create(:user) } - let(:task_created){ create(:task, user_id: user.id) } it 'タスクが削除できる' do login_as(user) - task_created + task visit tasks_path click_on 'Destroy' page.driver.browser.switch_to.alert.accept expect(page).to have_content 'Task was successfully destroyed.' - expect{Task.find(task_created.id)}.to raise_exception(ActiveRecord::RecordNotFound) + expect{Task.find(task.id)}.to raise_exception(ActiveRecord::RecordNotFound) end end context 'ログインしていない状態' do @@ -74,8 +69,6 @@ end describe 'タスクの詳細画面' do context 'ログインした状態' do - let(:user) { create(:user) } - let(:task){ create(:task) } it 'タスクの詳細に遷移できる' do login_as(user) visit task_path(task) @@ -83,7 +76,6 @@ end end context 'ログインしていない状態' do - let(:task){ create(:task) } it 'タスクの詳細に遷移できる' do visit task_path(task) expect(page).to have_content task.title @@ -91,8 +83,6 @@ end end describe 'タスクの詳細画面' do - let(:user) { create(:user) } - let(:task){ create(:task, user_id: user.id) } context 'ログインした状態' do it 'マイページにユーザーが新規作成したタスクが表示される' do login_as(user) @@ -102,9 +92,6 @@ expect(page).to have_content task.status end end - let(:user) { create(:user) } - let(:user_another) { create(:user, email: 'another@gmail.com') } - let(:task){ create(:task, user_id: user.id) } context 'ログインしていない状態' do it '他のユーザーのタスク編集ページへの遷移ができない' do login_as(user_another) From 1963ba069a08bae78efb51ba01fff6c21473223b Mon Sep 17 00:00:00 2001 From: yuji91 Date: Fri, 11 Oct 2019 16:02:18 +0900 Subject: [PATCH 19/28] Add helper user_form_button --- app/helpers/application_helper.rb | 1 + app/helpers/users_helper.rb | 16 ++++++++++++++++ app/views/users/_form.html.erb | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/helpers/users_helper.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..6ee31660d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,3 @@ module ApplicationHelper + include UsersHelper end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..6c0d84d95 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,16 @@ +module UsersHelper + def user_form_button + case params[:action] + when 'new' + 'SignUp' + when 'edit' + 'Update' + when 'create' + 'SignUp' + when 'update' + 'Update' + else + raise 'unexpected action' + end + end +end diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 6e357d107..bcd48c07c 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -24,6 +24,6 @@ <%= f.password_field :password_confirmation, class:'form-control' %>
- <%= f.submit 'Submit', class: "btn btn-primary" %> + <%= f.submit user_form_button, class: "btn btn-primary" %>
<% end %> From 6c0a437a96940a29a9145b3a465544fc60b784b5 Mon Sep 17 00:00:00 2001 From: yusuke Date: Fri, 11 Oct 2019 17:58:23 +0900 Subject: [PATCH 20/28] =?UTF-8?q?Fix:=20Signup=E3=82=92Submit=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index db3ee7a99..8fcfbf111 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -24,14 +24,14 @@ fill_in 'user_email', with: 'example@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'SignUp' + click_button 'Submit' expect(page).to have_content 'User was successfully created.' end end context '入力値が異常な状態' do it 'ユーザーの新規作成が失敗すること' do visit sign_up_path - click_button 'SignUp' + click_button 'Submit' expect(page).to have_content 'error' end end @@ -44,7 +44,7 @@ fill_in 'user_email', with: 'updated@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'SignUp' + click_button 'Submit' expect(page).to have_content 'User was successfully updated.' expect(page).to have_content 'updated@gmail.com' end @@ -56,7 +56,7 @@ fill_in 'user_email', with: '' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'SignUp' + click_button 'Submit' expect(page).to have_content 'error' end end From de465ac1f8db4a5d4f1ae922bcb79d3aca00e48c Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 12:04:45 +0900 Subject: [PATCH 21/28] =?UTF-8?q?Fix:=20=E7=99=BB=E9=8C=B2=E6=B8=88?= =?UTF-8?q?=E3=81=BF=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E4=BD=9C=E6=88=90=E3=80=81=E7=B7=A8?= =?UTF-8?q?=E9=9B=86=E3=81=8C=E5=A4=B1=E6=95=97=E3=81=99=E3=82=8B=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index 8fcfbf111..9be247e56 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -2,6 +2,7 @@ RSpec.describe 'Users', type: :system do let(:user) { create(:user) } + let(:user_another) { create(:user, email: 'another@gmail.com') } describe 'ログイン画面' do context '入力値が正常な状態' do it 'ログインが成功すること' do @@ -28,13 +29,24 @@ expect(page).to have_content 'User was successfully created.' end end - context '入力値が異常な状態' do + context '入力値が異常な状態(未入力)' do it 'ユーザーの新規作成が失敗すること' do visit sign_up_path click_button 'Submit' expect(page).to have_content 'error' end end + context '入力値が異常な状態(登録済みアドレス使用)' do + it 'ユーザーの新規作成が失敗すること' do + visit sign_up_path + user + fill_in 'user_email', with: 'example@gmail.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' + click_button 'Submit' + expect(page).to have_content 'Email has already been taken' + end + end end describe 'ユーザー編集画面' do context '入力値が正常な状態' do @@ -50,7 +62,7 @@ end end context '入力値が異常な状態' do - it 'ユーザーの編集ができるないこと' do + it 'ユーザーの編集ができないこと(未入力)' do login_as(user) visit edit_user_path(user) fill_in 'user_email', with: '' @@ -60,5 +72,17 @@ expect(page).to have_content 'error' end end + context '入力値が異常な状態' do + it 'ユーザーの編集ができないこと(登録済みアドレス使用)' do + login_as(user) + visit edit_user_path(user) + user_another + fill_in 'user_email', with: 'another@gmail.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' + click_button 'Submit' + expect(page).to have_content 'Email has already been taken' + end + end end end From eba18d2c90c49b21e09e18095bc5ab6694b5a286 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 12:05:51 +0900 Subject: [PATCH 22/28] =?UTF-8?q?Feature:=20fdescribe,=20fcontext=E3=81=AA?= =?UTF-8?q?=E3=81=A9=E3=82=92=E6=9C=89=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/spec_helper.rb | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66df..d54cc5fcf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,53 +44,53 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed + end end From 626f40d7d950696a8c670aa7644b62785bcf57b7 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 12:06:18 +0900 Subject: [PATCH 23/28] =?UTF-8?q?Feature:=20headless=20chrome=E3=81=AE?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/support/headless_chrome.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 spec/support/headless_chrome.rb diff --git a/spec/support/headless_chrome.rb b/spec/support/headless_chrome.rb new file mode 100644 index 000000000..df56314ce --- /dev/null +++ b/spec/support/headless_chrome.rb @@ -0,0 +1,5 @@ +RSpec.configure do |config| + config.before(:each, type: :system) do + driven_by :selenium_chrome_headless + end +end From 6602a651efb045816d12632d244eab05b2534603 Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 12:12:07 +0900 Subject: [PATCH 24/28] =?UTF-8?q?Fix:=20let=E3=81=A8describe=E3=81=AE?= =?UTF-8?q?=E9=96=93=E3=82=92=E4=B8=80=E8=A1=8C=E9=96=8B=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/task_spec.rb | 1 + spec/system/user_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/system/task_spec.rb b/spec/system/task_spec.rb index de8131b9a..96af6e923 100644 --- a/spec/system/task_spec.rb +++ b/spec/system/task_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' RSpec.describe 'Tasks', type: :system do + let(:user) { create(:user) } let(:user_another) { create(:user, email: 'another@gmail.com') } let(:task){ create(:task, user_id: user.id) } diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index 9be247e56..d4f08781d 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' RSpec.describe 'Users', type: :system do + let(:user) { create(:user) } let(:user_another) { create(:user, email: 'another@gmail.com') } describe 'ログイン画面' do From f19a61ff15dd1231396c661da3d6d9ff0dc00f8a Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 12:14:11 +0900 Subject: [PATCH 25/28] =?UTF-8?q?Fix:=20spec=5Fhelper=E3=81=AE=E4=B8=80?= =?UTF-8?q?=E9=83=A8=E3=82=92=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=A2?= =?UTF-8?q?=E3=82=A6=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/spec_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d54cc5fcf..339e2ee94 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,7 +64,7 @@ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! + # config.disable_monkey_patching! # Many RSpec users commonly either run the entire suite or an individual # file, and it's useful to allow more verbose output when running an @@ -73,24 +73,24 @@ # Use the documentation formatter for detailed output, # unless a formatter has already been configured # (e.g. via a command-line flag). - config.default_formatter = "doc" + # config.default_formatter = "doc" end # Print the 10 slowest examples and example groups at the # end of the spec run, to help surface which specs are running # particularly slow. - config.profile_examples = 10 + # config.profile_examples = 10 # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 - config.order = :random + # config.order = :random # Seed global randomization in this process using the `--seed` CLI option. # Setting this allows you to use `--seed` to deterministically reproduce # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. - Kernel.srand config.seed + # Kernel.srand config.seed end end From 6e821875dc5ca814a739b0717884c4f17e4ca199 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Tue, 15 Oct 2019 12:49:45 +0900 Subject: [PATCH 26/28] Add forbid invalid access for user edit, update, destroy --- app/controllers/users_controller.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a9c6dc679..d792a3285 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,7 @@ class UsersController < ApplicationController before_action :set_user, only: %i[show edit update destroy] skip_before_action :require_login, only: %i[new create] + before_action :forbid_invalid_access, only: %i[edit update destroy] def index @users = User.all @@ -44,4 +45,14 @@ def user_params :password_confirmation ) end + + def forbid_invalid_access + return if correct_user? + + redirect_to current_user, alert: 'Forbidden access.' + end + + def correct_user? + @user == current_user + end end From 83639dc56efa47a54cca8aca4edb7b356105df1a Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 14:48:17 +0900 Subject: [PATCH 27/28] =?UTF-8?q?Feature:=20=E4=BB=96=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E7=B7=A8=E9=9B=86=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=81=AB=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index d4f08781d..90c5f4918 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -62,8 +62,8 @@ expect(page).to have_content 'updated@gmail.com' end end - context '入力値が異常な状態' do - it 'ユーザーの編集ができないこと(未入力)' do + context '入力値が異常な状態(未入力)' do + it 'ユーザーの編集ができないこと' do login_as(user) visit edit_user_path(user) fill_in 'user_email', with: '' @@ -73,8 +73,8 @@ expect(page).to have_content 'error' end end - context '入力値が異常な状態' do - it 'ユーザーの編集ができないこと(登録済みアドレス使用)' do + context '入力値が異常な状態(登録済みアドレス使用)' do + it 'ユーザーの編集ができないこと' do login_as(user) visit edit_user_path(user) user_another @@ -85,5 +85,12 @@ expect(page).to have_content 'Email has already been taken' end end + context '異常系:他のユーザーのページにアクセス' do + it '編集画面に遷移できない' do + login_as(user) + visit edit_user_path(user_another) + expect(page).to have_content 'Forbidden access.' + end + end end end From aa52084db02a20b50c464888d37ee8122294236a Mon Sep 17 00:00:00 2001 From: yusuke Date: Tue, 15 Oct 2019 14:52:08 +0900 Subject: [PATCH 28/28] =?UTF-8?q?Fix:=20user=E3=81=AESubmit=E3=83=9C?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=92Signup,=20Update=E3=83=9C=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/user_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/system/user_spec.rb b/spec/system/user_spec.rb index 90c5f4918..d0d3d8f72 100644 --- a/spec/system/user_spec.rb +++ b/spec/system/user_spec.rb @@ -26,14 +26,14 @@ fill_in 'user_email', with: 'example@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'Submit' + click_button 'SignUp' expect(page).to have_content 'User was successfully created.' end end context '入力値が異常な状態(未入力)' do it 'ユーザーの新規作成が失敗すること' do visit sign_up_path - click_button 'Submit' + click_button 'SignUp' expect(page).to have_content 'error' end end @@ -44,7 +44,7 @@ fill_in 'user_email', with: 'example@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'Submit' + click_button 'SignUp' expect(page).to have_content 'Email has already been taken' end end @@ -57,7 +57,7 @@ fill_in 'user_email', with: 'updated@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'Submit' + click_button 'Update' expect(page).to have_content 'User was successfully updated.' expect(page).to have_content 'updated@gmail.com' end @@ -69,7 +69,7 @@ fill_in 'user_email', with: '' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'Submit' + click_button 'Update' expect(page).to have_content 'error' end end @@ -81,7 +81,7 @@ fill_in 'user_email', with: 'another@gmail.com' fill_in 'user_password', with: 'password' fill_in 'user_password_confirmation', with: 'password' - click_button 'Submit' + click_button 'Update' expect(page).to have_content 'Email has already been taken' end end