Skip to content

Commit 6cbb39d

Browse files
committed
test: Improve test suite setup
1 parent d19fc7d commit 6cbb39d

18 files changed

Lines changed: 110 additions & 205 deletions

File tree

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ gem 'capybara'
4747
gem 'cuprite'
4848
gem 'rspec_junit_formatter'
4949
gem 'rspec-rails'
50-
gem 'rspec-retry'
5150
gem 'simplecov', require: false
5251

5352
# Linters

spec/dummy/app/admin/posts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
f.input :author
4545
f.input :title
4646
f.input :summary, as: :quill_editor, input_html: { data: { options: { modules: { toolbar: toolbar } } } }
47-
f.input :description, as: :quill_editor, input_html: { data: { options: { modules: { toolbar: toolbar } } } }
47+
f.input :description, as: :quill_editor # using default options
4848
f.input :category
4949
f.input :dt
5050
f.input :position

spec/dummy/app/admin/tags.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
22

33
ActiveAdmin.register Tag do
4+
permit_params :name
45
end

spec/dummy/app/models/post.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
class Post < ApplicationRecord
4-
# enum state: %i[available unavailable arriving]
5-
64
belongs_to :author, inverse_of: :posts, autosave: true
75

86
has_one :author_profile, through: :author, source: :profile
@@ -28,12 +26,12 @@ def upper_title
2826
end
2927

3028
class << self
31-
def ransackable_attributes(auth_object = nil)
32-
%w[author_id category created_at description dt id position published summary title updated_at]
29+
def ransackable_associations(_auth_object = nil)
30+
%w[author author_profile post_tags tags images_attachments images_blobs]
3331
end
3432

35-
def ransackable_associations(auth_object = nil)
36-
%w[author author_profile images_attachments images_blobs post_tags tags]
33+
def ransackable_attributes(_auth_object = nil)
34+
%w[author_id category created_at description dt id position published title summary updated_at]
3735
end
3836
end
3937
end

spec/dummy/app/models/profile.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
class Profile < ApplicationRecord
44
belongs_to :author, inverse_of: :profile, touch: true
55

6-
# has_rich_text :description
7-
8-
# def to_s
9-
# description
10-
# end
6+
def to_s
7+
description
8+
end
119

1210
class << self
13-
def ransackable_associations(auth_object = nil)
11+
def ransackable_associations(_auth_object = nil)
1412
%w[author]
1513
end
1614

spec/dummy/config/application.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
require_relative 'boot'
22

33
require 'rails/all'
4-
require 'sprockets/railtie'
54

65
Bundler.require(*Rails.groups)
76

87
module Dummy
98
class Application < Rails::Application
10-
# Initialize configuration defaults for originally generated Rails version.
11-
config.load_defaults 6.0 if Rails::VERSION::MAJOR == 6
9+
config.load_defaults Rails::VERSION::STRING.to_f
1210

13-
# Settings in config/environments/* take precedence over those specified here.
14-
# Application configuration can go into files in config/initializers
15-
# -- all .rb files in that directory are automatically loaded after loading
16-
# the framework and any gems in your application.
11+
config.active_support.deprecation = :raise
1712

18-
###
19-
20-
config.active_record.legacy_connection_handling = false if Gem::Version.new(Rails.version) < Gem::Version.new('7.1')
13+
if Gem::Version.new(Rails.version) < Gem::Version.new('7.1')
14+
config.active_record.legacy_connection_handling = false
15+
end
2116

22-
config.before_configuration do
23-
ActiveSupport::Cache.format_version = 7.0 if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
17+
if Gem::Version.new(Rails.version) > Gem::Version.new('7.0')
18+
config.before_configuration do
19+
ActiveSupport::Cache.format_version = 7.0
20+
end
2421
end
2522
end
2623
end

spec/dummy/config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default: &default
66
development:
77
<<: *default
88
database: db/development.sqlite3
9-
schema_dump: schema_development.rb
9+
schema_dump: schema-dev.rb
1010

1111
test:
1212
<<: *default
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
ActiveSupport::Reloader.to_prepare do
1+
Rails.application.reloader.to_prepare do
22
ActiveStorage::Attachment.class_eval do
3-
def self.ransackable_attributes(auth_object = nil)
4-
%w[blob_id created_at id name record_id record_type]
3+
class << self
4+
def ransackable_attributes(auth_object = nil)
5+
%w[blob_id created_at id name record_id record_type]
6+
end
57
end
68
end
79
end

spec/dummy/db/schema_development.rb

Lines changed: 0 additions & 99 deletions
This file was deleted.

spec/dummy/db/seeds.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
(11..20).each do |i|
88
age = 21 + 3 * (i - 10)
99
attrs = { name: "Author #{i}", age: age, email: "some@email#{i}.com" }
10-
Author.find_or_create_by!(attrs) do |author|
10+
Author.find_or_create_by!(name: "Author #{i}") do |author|
11+
author.assign_attributes(attrs)
1112
author.profile = Profile.new(description: "Profile description for Author #{i}") if (i % 3).zero?
1213
end
1314
end
@@ -19,6 +20,8 @@
1920
title: "Post #{i}",
2021
author_id: authors.sample,
2122
position: rand(100),
23+
summary: "<p><em>Summary</em> for post #{i}</p>",
24+
description: "<p><strong>Some bold</strong> <em>Some italic</em> <u>Some underline</u> [#{i}]</p>",
2225
created_at: Time.now - rand(3600).seconds
2326
}
2427
attrs[:category] = 'news' if (i % 4).zero?

0 commit comments

Comments
 (0)