Skip to content

Commit

Permalink
Merge pull request #320 from YukiWatanabe824/dev
Browse files Browse the repository at this point in the history
リリース
  • Loading branch information
YukiWatanabe824 committed Jun 8, 2024
2 parents f41df70 + b45dad9 commit 7c88cd3
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require spec_helper
--format documentation
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ gem 'turbo-rails'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

group :development, :test do
gem 'factory_bot_rails', require: false
gem 'rspec-rails', require: false
gem 'rubocop-capybara', require: false
gem 'rubocop-fjord', require: false
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
gem 'slim_lint', require: false
end

Expand Down
38 changes: 38 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ GEM
warden (~> 1.2.3)
devise-i18n (1.12.0)
devise (>= 4.9.0)
diff-lcs (1.5.1)
docile (1.4.0)
dockerfile-rails (1.6.5)
rails (>= 3.0.0)
drb (2.2.0)
ruby2_keywords
erubi (1.12.0)
factory_bot (6.4.5)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
Expand Down Expand Up @@ -300,6 +306,23 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.1.0)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.12)
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.60.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand All @@ -313,6 +336,10 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-fjord (0.3.0)
rubocop (>= 1.0)
rubocop-performance
Expand All @@ -324,6 +351,13 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
ruby-progressbar (1.13.0)
ruby-vips (2.2.0)
ffi (~> 1.12)
Expand Down Expand Up @@ -417,6 +451,7 @@ DEPENDENCIES
devise
devise-i18n
dockerfile-rails
factory_bot_rails
html2slim
image_processing
importmap-rails
Expand All @@ -431,8 +466,11 @@ DEPENDENCIES
rails (= 7.1.3)
rails-i18n
redis
rspec-rails
rubocop-capybara
rubocop-fjord
rubocop-rails
rubocop-rspec
selenium-webdriver
sentry-rails
simplecov
Expand Down
27 changes: 27 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
18 changes: 13 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "boot"
require_relative 'boot'

require "rails/all"
require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand All @@ -14,16 +14,24 @@ class Application < Rails::Application
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w(assets tasks))
config.autoload_lib(ignore: %w[assets tasks])

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
config.time_zone = "Asia/Tokyo"
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
config.time_zone = 'Asia/Tokyo'
config.i18n.load_path += Dir[Rails.root.join('config/locales/**/*.{rb,yml}').to_s]
config.i18n.default_locale = :ja
# config.eager_load_paths << Rails.root.join("extras")

# RSpec's generate conf
config.generators do |g|
g.test_framework :rspec,
view_specs: false,
helper_specs: false,
routing_specs: false
end
end
end
24 changes: 24 additions & 0 deletions spec/factories/spots.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

FactoryBot.define do
factory :spot do
sequence(:title) { |n| "#{n}th test title" }
accident_date { '2014-01-01 00:00:01' }

trait :make_by_admin_user do
accident_type { '自損' }
contents { '走行中に左折レーンに入ってしまい直進しようとした際に、後方車列を振り向いて確認した際にふらついて落車' }
longitude { '139.774373' }
latitude { '35.684420' }
association :user, :admin_user
end

trait :make_by_standard_user do
accident_type { '人身' }
contents { '走行中に左折レーンに入ってしまい直進しようとした際に、後方車列を振り向いて確認した際にふらついて落車' }
longitude { '139.753003' }
latitude { '35.685814' }
association :user, :not_admin_user
end
end
end
17 changes: 17 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user do
sequence(:email) { |n| "xxx#{n}@example.jp" }
sequence(:password) { |n| "123456789ab#{n}" }

trait :admin_user do
name { 'yuki' }
admin { 'true' }
end

trait :not_admin_user do
name { 'not_admin' }
end
end
end
12 changes: 12 additions & 0 deletions spec/models/spot_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Spot, type: :model do
it 'spotの所有者が.owned_byでわかる' do
spot = FactoryBot.create(:spot, :make_by_admin_user)
user_not_owned_spot = FactoryBot.create(:user, :not_admin_user)
expect(spot.owned_by?(spot.user)).to be_truthy
expect(spot.owned_by?(user_not_owned_spot)).to be_falsey
end
end
16 changes: 16 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe User, type: :model do
it 'adminかどうか' do
admin_user = FactoryBot.create(:admin_user)
not_admin_user = FactoryBot.create(:not_admin_user)
expect(admin_user.admin?).to be_truthy
expect(not_admin_user.admin?).to be_falsey
end

it '36桁のユニークIDが生成できているかどうか' do
expect(User.create_unique_string.length).to eq 36
end
end
69 changes: 69 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
require 'factory_bot_rails'

ENV['RAILS_ENV'] = 'test'
require_relative '../config/environment'
# 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.
#
# Rails.root.glob('spec/support/**/*.rb').sort.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
abort e.to_s.strip
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_paths = [
Rails.root.join('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

# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

# 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://rspec.info/features/6-0/rspec-rails
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
Loading

0 comments on commit 7c88cd3

Please sign in to comment.