diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/everydayrails-rspec-2017.iml b/.idea/everydayrails-rspec-2017.iml new file mode 100644 index 00000000..0917b2f0 --- /dev/null +++ b/.idea/everydayrails-rspec-2017.iml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..2e9a8acc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..50fd8b81 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Gemfile b/Gemfile index 29fcdeef..0f0e6773 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,8 @@ group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'capybara', '~> 2.13.0' gem 'selenium-webdriver' + gem 'rspec-rails', '~> 3.6.0' + gem 'factory_bot_rails', '~> 4.10.0' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 45f1595d..29e9ff72 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,55 +1,55 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.1.1) - actionpack (= 5.1.1) + actioncable (5.1.7) + actionpack (= 5.1.7) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.1) - actionpack (= 5.1.1) - actionview (= 5.1.1) - activejob (= 5.1.1) + actionmailer (5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.1) - actionview (= 5.1.1) - activesupport (= 5.1.1) + actionpack (5.1.7) + actionview (= 5.1.7) + activesupport (= 5.1.7) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.1) - activesupport (= 5.1.1) + actionview (5.1.7) + activesupport (= 5.1.7) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.1) - activesupport (= 5.1.1) + activejob (5.1.7) + activesupport (= 5.1.7) globalid (>= 0.3.6) - activemodel (5.1.1) - activesupport (= 5.1.1) - activerecord (5.1.1) - activemodel (= 5.1.1) - activesupport (= 5.1.1) + activemodel (5.1.7) + activesupport (= 5.1.7) + activerecord (5.1.7) + activemodel (= 5.1.7) + activesupport (= 5.1.7) arel (~> 8.0) - activesupport (5.1.1) + activesupport (5.1.7) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.5.1) - public_suffix (~> 2.0, >= 2.0.2) + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) arel (8.0.0) - autoprefixer-rails (6.7.7.2) - execjs - bcrypt (3.1.12) - bindex (0.5.0) - bootstrap-sass (3.3.7) + autoprefixer-rails (10.2.5.1) + execjs (> 0) + bcrypt (3.1.16) + bindex (0.8.1) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) - builder (3.2.3) - byebug (9.0.6) + sassc (>= 2.0.0) + builder (3.2.4) + byebug (11.1.3) capybara (2.13.0) addressable mime-types (>= 1.16) @@ -57,41 +57,42 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - childprocess (0.6.3) - ffi (~> 1.0, >= 1.0.11) + childprocess (3.0.0) climate_control (0.2.0) - cocaine (0.5.8) - climate_control (>= 0.0.3, < 1.0) - coffee-rails (4.2.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.2.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.4) - devise (4.4.3) + concurrent-ruby (1.1.9) + crass (1.0.6) + devise (4.8.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 6.0) + railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.3) - erubi (1.7.1) - execjs (2.7.0) - faker (1.7.3) - i18n (~> 0.5) - ffi (1.9.18) - geocoder (1.4.9) - globalid (0.4.0) + diff-lcs (1.4.4) + erubi (1.10.0) + execjs (2.8.1) + factory_bot (4.10.0) + activesupport (>= 3.0.0) + factory_bot_rails (4.10.0) + factory_bot (~> 4.10.0) + railties (>= 3.0.0) + faker (2.18.0) + i18n (>= 1.6, < 2) + ffi (1.15.3) + geocoder (1.6.7) + globalid (0.4.2) activesupport (>= 4.2.0) - i18n (0.9.5) + i18n (1.8.10) concurrent-ruby (~> 1.0) - jbuilder (2.6.3) - activesupport (>= 3.0.0, < 5.2) - multi_json (~> 1.2) - jquery-rails (4.3.1) + jbuilder (2.11.2) + activesupport (>= 5.0.0) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -99,64 +100,68 @@ GEM rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.2.2) + loofah (2.10.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.5) - mime-types (>= 1.16, < 4) - method_source (0.9.0) - mime-types (3.1) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) + mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mimemagic (0.3.2) - mini_portile2 (2.3.0) - minitest (5.11.3) - multi_json (1.12.1) - nio4r (2.0.0) - nokogiri (1.8.4) - mini_portile2 (~> 2.3.0) + mime-types-data (3.2021.0704) + mimemagic (0.3.10) + nokogiri (~> 1) + rake + mini_mime (1.1.0) + mini_portile2 (2.5.3) + minitest (5.14.4) + nio4r (2.5.7) + nokogiri (1.11.7) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) orm_adapter (0.5.0) - paperclip (5.1.0) + paperclip (6.1.0) activemodel (>= 4.2.0) activesupport (>= 4.2.0) - cocaine (~> 0.5.5) mime-types mimemagic (~> 0.3.0) - public_suffix (2.0.5) - puma (3.8.2) - rack (2.0.5) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.1.1) - actioncable (= 5.1.1) - actionmailer (= 5.1.1) - actionpack (= 5.1.1) - actionview (= 5.1.1) - activejob (= 5.1.1) - activemodel (= 5.1.1) - activerecord (= 5.1.1) - activesupport (= 5.1.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.1.1) + terrapin (~> 0.6.0) + public_suffix (4.0.6) + puma (3.12.6) + racc (1.5.2) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.1.7) + actioncable (= 5.1.7) + actionmailer (= 5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) + activemodel (= 5.1.7) + activerecord (= 5.1.7) + activesupport (= 5.1.7) + bundler (>= 1.3.0) + railties (= 5.1.7) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.1.1) - actionpack (= 5.1.1) - activesupport (= 5.1.1) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.1.7) + actionpack (= 5.1.7) + activesupport (= 5.1.7) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.3.1) - rb-fsevent (0.9.8) - rb-inotify (0.9.8) - ffi (>= 0.5.0) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) + rake (13.0.6) + rb-fsevent (0.11.0) + rb-inotify (0.10.1) + ffi (~> 1.0) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) rspec-core (3.6.0) rspec-support (~> 3.6.0) rspec-expectations (3.6.0) @@ -165,7 +170,7 @@ GEM rspec-mocks (3.6.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.6.0) - rspec-rails (3.6.0) + rspec-rails (3.6.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -175,55 +180,60 @@ GEM rspec-support (~> 3.6.0) rspec-support (3.6.0) ruby_dep (1.5.0) - rubyzip (1.2.1) - sass (3.4.23) - sass-rails (5.0.6) + rubyzip (2.3.2) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - selenium-webdriver (3.4.0) - childprocess (~> 0.5) - rubyzip (~> 1.0) - websocket (~> 1.0) - spring (2.0.1) - activesupport (>= 4.2) + sassc (2.4.0) + ffi (~> 1.9) + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) + spring (2.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.0) + sqlite3 (1.4.2) + terrapin (0.6.0) + climate_control (>= 0.0.3, < 1.0) + thor (1.1.0) thread_safe (0.3.6) - tilt (2.0.7) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) - tzinfo (1.2.5) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.9) thread_safe (~> 0.1) - uglifier (3.2.0) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - warden (1.2.7) - rack (>= 1.0) - web-console (3.5.0) + warden (1.2.9) + rack (>= 2.0.9) + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket (1.2.4) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) - xpath (2.0.0) + websocket-extensions (0.1.5) + xpath (2.1.0) nokogiri (~> 1.3) PLATFORMS @@ -235,6 +245,7 @@ DEPENDENCIES capybara (~> 2.13.0) coffee-rails (~> 4.2) devise + factory_bot_rails (~> 4.10.0) faker geocoder jbuilder (~> 2.5) @@ -256,4 +267,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.14.6 + 1.17.2 diff --git a/config/application.rb b/config/application.rb index 6ea74494..c6e90abb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,7 +17,6 @@ class Application < Rails::Application config.generators do |g| g.test_framework :rspec, - fixtures: false, view_specs: false, helper_specs: false, routing_specs: false diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb new file mode 100644 index 00000000..9f80ba61 --- /dev/null +++ b/spec/factories/notes.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :note do + message "My important note." + association :project + association { project.owner } + end +end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb new file mode 100644 index 00000000..0321ed00 --- /dev/null +++ b/spec/factories/projects.rb @@ -0,0 +1,52 @@ +FactoryBot.define do + # factory :project do + # sequence(:name) { |n| "Project #{n}" } + # description "Sample project for testing purposes" + # due_on 1.week.from_now + # association :owner + # + # # 昨日が締め切りのプロジェクト + # factory :project_due_yesterday do + # due_on 1.week.ago + # end + # + # # 今日が締め切りのプロジェクト + # factory :project_due_today do + # due_on Date.current.in_time_zone + # end + # + # # 明日が締め切りのプロジェクト + # factory :project_due_tomorrow do + # due_on 1.day.from_now + # end + # end + + factory :project do + sequence(:name) { |n| "Project #{n}" } + description "Sample project for testing purposes" + due_on 1.week.from_now + association :owner + + # メモ付きのプロジェクト + trait :with_notes do + after(:create) { |project| create_list(:note, 5, project: project) } + end + + # 締め切りが昨日 + trait :due_yesterday do + due_on 1.day.ago + end + + # 締め切りが今日 + trait :due_today do + due_on Date.current.in_time_zone + end + + # 締め切りが明日 + trait :due_today do + due_on 1.day.from_now + end + end + + +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 00000000..653fa4c7 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :user, aliases: [:owner] do + first_name "Aaron" + last_name "Sumner" + sequence(:email) { |n| "tester#{n}@example.com" } + password "dottle-nouveau-pavilion-tights-furze" + end +end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 98377c55..c1dafc47 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -1,6 +1,14 @@ require 'rails_helper' RSpec.describe Note, type: :model do + + # ファクトリで関連するデータを生成する + it "generates associated data from a factory" do + note = FactoryBot.create(:note) + puts "This note's project is #{note.project.inspect}" + puts "This note's user is #{note.user.inspect}" + end + before do @user = User.create( first_name: "Joe", diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 13b610ee..81ce789b 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,6 +1,30 @@ require 'rails_helper' RSpec.describe Project, type: :model do + # たくさんのメモがついていること + it "can have many notes" do + project = FactoryBot.create(:project, :with_notes) + expect(project.notes.lenght).to eq 5 + end + + #締切日が過ぎていれば遅延していること + it "is late when the due date is past today" do + project = FactoryBot.create(:project, :due_yesterday) + expect(project).to be_late + end + + # 締切日が今日ならスケジュール通りであること + it "is on time when the due date is today" do + project = FactoryBot.create(:project, :due_today) + expect(project).to_not be_late + end + + # 締切日が未来ならスケジュール通りであること + it "is on time when the due date is today" do + project = FactoryBot.create(:project, :due_today) + expect(project).to_not be_late + end + it "does not allow duplicate project names per user" do user = User.create( first_name: "Joe", diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 02097563..8196c99d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,12 @@ require 'rails_helper' +describe User do + # 有効なファクトリを持つこと + it "has a valid factory" do + expect(FactoryBot.build(:user)).to be_valid + end +end + RSpec.describe User, type: :model do it "is valid with a first name, last name and email, and password" do user = User.new( @@ -12,46 +19,32 @@ end it "is invalid without a first name" do - user = User.new(first_name: nil) + user = FactoryBot.build(:user, first_name: nil) user.valid? expect(user.errors[:first_name]).to include("can't be blank") end it "is invalid without a last name" do - user = User.new(last_name: nil) + user = Factory_bot.build(:user, last_name: nil) user.valid? expect(user.errors[:last_name]).to include("can't be blank") end it "is invalid without an email address" do - user = User.new(email: nil) + user.Factory_bot.build(:user, email: nil) user.valid? expect(user.errors[:email]).to include("can't be blank") end it "is invalid with a duplicate email address" do - User.create( - first_name: "Joe", - last_name: "Tester", - email: "tester@example.com", - password: "dottle-nouveau-pavilion-tights-furze", - ) - user = User.new( - first_name: "Jane", - last_name: "Tester", - email: "tester@example.com", - password: "dottle-nouveau-pavilion-tights-furze", - ) + FactoryBot.create(:user, email: "aaron@example.com") + user = FactoryBot.build(:user, email: "aaron@example.com") user.valid? expect(user.errors[:email]).to include("has already been taken") end it "returns a user's full name as a string" do - user = User.new( - first_name: "John", - last_name: "Doe", - email: "johndoe@example.com", - ) + user = FactoryBot.build(:user, first_name: "John", last_name: "Doe") expect(user.name).to eq "John Doe" end end