activerecord-import 0.25.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/test.yaml +151 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +74 -8
- data/.rubocop_todo.yml +10 -16
- data/Brewfile +3 -1
- data/CHANGELOG.md +232 -2
- data/Dockerfile +23 -0
- data/Gemfile +26 -14
- data/LICENSE +21 -56
- data/README.markdown +612 -21
- data/Rakefile +4 -1
- data/activerecord-import.gemspec +6 -5
- data/benchmarks/benchmark.rb +10 -4
- data/benchmarks/lib/base.rb +4 -2
- data/benchmarks/lib/cli_parser.rb +4 -2
- data/benchmarks/lib/float.rb +2 -0
- data/benchmarks/lib/mysql2_benchmark.rb +2 -0
- data/benchmarks/lib/output_to_csv.rb +2 -0
- data/benchmarks/lib/output_to_html.rb +4 -2
- data/benchmarks/models/test_innodb.rb +2 -0
- data/benchmarks/models/test_memory.rb +2 -0
- data/benchmarks/models/test_myisam.rb +2 -0
- data/benchmarks/schema/{mysql_schema.rb → mysql2_schema.rb} +2 -0
- data/docker-compose.yml +34 -0
- data/gemfiles/4.2.gemfile +2 -0
- data/gemfiles/5.0.gemfile +2 -0
- data/gemfiles/5.1.gemfile +2 -0
- data/gemfiles/5.2.gemfile +2 -0
- data/gemfiles/6.0.gemfile +4 -0
- data/gemfiles/6.1.gemfile +4 -0
- data/gemfiles/7.0.gemfile +4 -0
- data/gemfiles/7.1.gemfile +3 -0
- data/lib/activerecord-import/active_record/adapters/abstract_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb +6 -4
- data/lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/jdbcsqlite3_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/postgresql_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/trilogy_adapter.rb +8 -0
- data/lib/activerecord-import/adapters/abstract_adapter.rb +15 -6
- data/lib/activerecord-import/adapters/em_mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/mysql2_adapter.rb +2 -0
- data/lib/activerecord-import/adapters/mysql_adapter.rb +34 -29
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +74 -55
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +138 -13
- data/lib/activerecord-import/adapters/trilogy_adapter.rb +7 -0
- data/lib/activerecord-import/base.rb +11 -2
- data/lib/activerecord-import/import.rb +290 -114
- data/lib/activerecord-import/mysql2.rb +2 -0
- data/lib/activerecord-import/postgresql.rb +2 -0
- data/lib/activerecord-import/sqlite3.rb +2 -0
- data/lib/activerecord-import/synchronize.rb +4 -2
- data/lib/activerecord-import/value_sets_parser.rb +5 -0
- data/lib/activerecord-import/version.rb +3 -1
- data/lib/activerecord-import.rb +2 -1
- data/test/adapters/jdbcmysql.rb +2 -0
- data/test/adapters/jdbcpostgresql.rb +2 -0
- data/test/adapters/jdbcsqlite3.rb +2 -0
- data/test/adapters/makara_postgis.rb +2 -0
- data/test/adapters/mysql2.rb +2 -0
- data/test/adapters/mysql2_makara.rb +2 -0
- data/test/adapters/mysql2spatial.rb +2 -0
- data/test/adapters/postgis.rb +2 -0
- data/test/adapters/postgresql.rb +2 -0
- data/test/adapters/postgresql_makara.rb +2 -0
- data/test/adapters/seamless_database_pool.rb +2 -0
- data/test/adapters/spatialite.rb +2 -0
- data/test/adapters/sqlite3.rb +2 -0
- data/test/adapters/trilogy.rb +9 -0
- data/test/database.yml.sample +7 -0
- data/test/{travis → github}/database.yml +7 -1
- data/test/import_test.rb +151 -8
- data/test/jdbcmysql/import_test.rb +5 -3
- data/test/jdbcpostgresql/import_test.rb +4 -2
- data/test/jdbcsqlite3/import_test.rb +4 -2
- data/test/makara_postgis/import_test.rb +4 -2
- data/test/models/account.rb +2 -0
- data/test/models/alarm.rb +2 -0
- data/test/models/animal.rb +8 -0
- data/test/models/author.rb +7 -0
- data/test/models/bike_maker.rb +3 -0
- data/test/models/book.rb +7 -2
- data/test/models/car.rb +2 -0
- data/test/models/card.rb +5 -0
- data/test/models/chapter.rb +2 -0
- data/test/models/composite_book.rb +19 -0
- data/test/models/composite_chapter.rb +9 -0
- data/test/models/customer.rb +18 -0
- data/test/models/deck.rb +8 -0
- data/test/models/dictionary.rb +2 -0
- data/test/models/discount.rb +2 -0
- data/test/models/end_note.rb +2 -0
- data/test/models/group.rb +2 -0
- data/test/models/order.rb +17 -0
- data/test/models/playing_card.rb +4 -0
- data/test/models/promotion.rb +2 -0
- data/test/models/question.rb +2 -0
- data/test/models/rule.rb +2 -0
- data/test/models/tag.rb +9 -1
- data/test/models/tag_alias.rb +11 -0
- data/test/models/topic.rb +7 -0
- data/test/models/user.rb +2 -0
- data/test/models/user_token.rb +3 -0
- data/test/models/vendor.rb +2 -0
- data/test/models/widget.rb +2 -0
- data/test/mysql2/import_test.rb +5 -3
- data/test/mysql2_makara/import_test.rb +5 -3
- data/test/mysqlspatial2/import_test.rb +5 -3
- data/test/postgis/import_test.rb +4 -2
- data/test/postgresql/import_test.rb +4 -2
- data/test/schema/generic_schema.rb +37 -1
- data/test/schema/jdbcpostgresql_schema.rb +3 -1
- data/test/schema/mysql2_schema.rb +2 -0
- data/test/schema/postgis_schema.rb +3 -1
- data/test/schema/postgresql_schema.rb +49 -0
- data/test/schema/sqlite3_schema.rb +15 -0
- data/test/schema/version.rb +2 -0
- data/test/sqlite3/import_test.rb +4 -2
- data/test/support/active_support/test_case_extensions.rb +2 -0
- data/test/support/assertions.rb +2 -0
- data/test/support/factories.rb +10 -8
- data/test/support/generate.rb +10 -8
- data/test/support/mysql/import_examples.rb +2 -1
- data/test/support/postgresql/import_examples.rb +152 -3
- data/test/support/shared_examples/on_duplicate_key_ignore.rb +2 -0
- data/test/support/shared_examples/on_duplicate_key_update.rb +122 -9
- data/test/support/shared_examples/recursive_import.rb +128 -2
- data/test/support/sqlite3/import_examples.rb +191 -26
- data/test/synchronize_test.rb +2 -0
- data/test/test_helper.rb +34 -7
- data/test/trilogy/import_test.rb +7 -0
- data/test/value_sets_bytes_parser_test.rb +3 -1
- data/test/value_sets_records_parser_test.rb +3 -1
- metadata +46 -16
- data/.travis.yml +0 -71
- data/gemfiles/3.2.gemfile +0 -2
- data/gemfiles/4.0.gemfile +0 -2
- data/gemfiles/4.1.gemfile +0 -2
data/test/models/group.rb
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Order < ActiveRecord::Base
|
|
4
|
+
unless ENV["SKIP_COMPOSITE_PK"]
|
|
5
|
+
if ENV['AR_VERSION'].to_f <= 7.0
|
|
6
|
+
belongs_to :customer,
|
|
7
|
+
inverse_of: :orders,
|
|
8
|
+
primary_key: %i(account_id id),
|
|
9
|
+
foreign_key: %i(account_id customer_id)
|
|
10
|
+
else
|
|
11
|
+
belongs_to :customer,
|
|
12
|
+
inverse_of: :orders,
|
|
13
|
+
primary_key: %i(account_id id),
|
|
14
|
+
query_constraints: %i(account_id customer_id)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/test/models/promotion.rb
CHANGED
data/test/models/question.rb
CHANGED
data/test/models/rule.rb
CHANGED
data/test/models/tag.rb
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Tag < ActiveRecord::Base
|
|
2
|
-
|
|
4
|
+
if ENV['AR_VERSION'].to_f <= 7.0
|
|
5
|
+
self.primary_keys = :tag_id, :publisher_id unless ENV["SKIP_COMPOSITE_PK"]
|
|
6
|
+
else
|
|
7
|
+
self.primary_key = [:tag_id, :publisher_id] unless ENV["SKIP_COMPOSITE_PK"]
|
|
8
|
+
end
|
|
9
|
+
self.primary_key = [:tag_id, :publisher_id] unless ENV["SKIP_COMPOSITE_PK"]
|
|
3
10
|
has_many :books, inverse_of: :tag
|
|
11
|
+
has_many :tag_aliases, inverse_of: :tag
|
|
4
12
|
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class TagAlias < ActiveRecord::Base
|
|
4
|
+
unless ENV["SKIP_COMPOSITE_PK"]
|
|
5
|
+
if ENV['AR_VERSION'].to_f <= 7.0
|
|
6
|
+
belongs_to :tag, foreign_key: [:tag_id, :parent_id], required: true
|
|
7
|
+
else
|
|
8
|
+
belongs_to :tag, query_constraints: [:tag_id, :parent_id], required: true
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/test/models/topic.rb
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Topic < ActiveRecord::Base
|
|
4
|
+
if ENV['AR_VERSION'].to_i >= 6.0
|
|
5
|
+
self.ignored_columns = [:priority]
|
|
6
|
+
end
|
|
7
|
+
alias_attribute :name, :title
|
|
8
|
+
|
|
2
9
|
validates_presence_of :author_name
|
|
3
10
|
validates :title, numericality: { only_integer: true }, on: :context_test
|
|
4
11
|
validates :title, uniqueness: true
|
data/test/models/user.rb
CHANGED
data/test/models/user_token.rb
CHANGED
data/test/models/vendor.rb
CHANGED
data/test/models/widget.rb
CHANGED
data/test/mysql2/import_test.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
4
6
|
|
|
5
7
|
should_support_mysql_import_functionality
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
4
|
-
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
5
7
|
|
|
6
8
|
should_support_mysql_import_functionality
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)
|
|
4
|
-
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
|
|
5
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
|
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")
|
|
5
7
|
|
|
6
8
|
should_support_mysql_import_functionality
|
data/test/postgis/import_test.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_postgresql_import_functionality
|
|
5
7
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/postgresql/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_postgresql_import_functionality
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
ActiveRecord::Schema.define do
|
|
2
4
|
create_table :schema_info, force: :cascade do |t|
|
|
3
|
-
t.integer :version
|
|
5
|
+
t.integer :version
|
|
4
6
|
end
|
|
7
|
+
add_index :schema_info, :version, unique: true
|
|
8
|
+
|
|
5
9
|
SchemaInfo.create version: SchemaInfo::VERSION
|
|
6
10
|
|
|
7
11
|
create_table :group, force: :cascade do |t|
|
|
@@ -20,6 +24,7 @@ ActiveRecord::Schema.define do
|
|
|
20
24
|
t.boolean :approved, default: '1'
|
|
21
25
|
t.integer :replies_count
|
|
22
26
|
t.integer :parent_id
|
|
27
|
+
t.integer :priority, default: 0
|
|
23
28
|
t.string :type
|
|
24
29
|
t.datetime :created_at
|
|
25
30
|
t.datetime :created_on
|
|
@@ -52,6 +57,20 @@ ActiveRecord::Schema.define do
|
|
|
52
57
|
t.string :name
|
|
53
58
|
end
|
|
54
59
|
|
|
60
|
+
create_table :cards, force: :cascade do |t|
|
|
61
|
+
t.string :name
|
|
62
|
+
t.string :deck_type
|
|
63
|
+
t.integer :deck_id
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
create_table :decks, force: :cascade do |t|
|
|
67
|
+
t.string :name
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
create_table :playing_cards, force: :cascade do |t|
|
|
71
|
+
t.string :name
|
|
72
|
+
end
|
|
73
|
+
|
|
55
74
|
create_table :books, force: :cascade do |t|
|
|
56
75
|
t.string :title, null: false
|
|
57
76
|
t.string :publisher, null: false, default: 'Default Publisher'
|
|
@@ -190,5 +209,22 @@ ActiveRecord::Schema.define do
|
|
|
190
209
|
PRIMARY KEY (tag_id, publisher_id)
|
|
191
210
|
);
|
|
192
211
|
).split.join(' ').strip
|
|
212
|
+
|
|
213
|
+
create_table :tag_aliases, force: :cascade do |t|
|
|
214
|
+
t.integer :tag_id, null: false
|
|
215
|
+
t.integer :parent_id, null: false
|
|
216
|
+
t.string :alias, null: false
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
create_table :customers, force: :cascade do |t|
|
|
221
|
+
t.integer :account_id
|
|
222
|
+
t.string :name
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
create_table :orders, force: :cascade do |t|
|
|
226
|
+
t.integer :account_id
|
|
227
|
+
t.integer :customer_id
|
|
228
|
+
t.integer :amount
|
|
193
229
|
end
|
|
194
230
|
end
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
ActiveRecord::Schema.define do
|
|
2
4
|
execute('CREATE extension IF NOT EXISTS "hstore";')
|
|
3
5
|
execute('CREATE extension IF NOT EXISTS "pgcrypto";')
|
|
4
6
|
execute('CREATE extension IF NOT EXISTS "uuid-ossp";')
|
|
5
7
|
|
|
8
|
+
# create ENUM if it does not exist yet
|
|
9
|
+
begin
|
|
10
|
+
execute('CREATE TYPE vendor_type AS ENUM (\'wholesaler\', \'retailer\');')
|
|
11
|
+
rescue ActiveRecord::StatementInvalid
|
|
12
|
+
execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'wholesaler\';')
|
|
13
|
+
execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'retailer\';')
|
|
14
|
+
end
|
|
15
|
+
|
|
6
16
|
create_table :vendors, id: :uuid, force: :cascade do |t|
|
|
7
17
|
t.string :name, null: true
|
|
18
|
+
t.text :hours
|
|
8
19
|
t.text :preferences
|
|
9
20
|
|
|
10
21
|
if t.respond_to?(:json)
|
|
22
|
+
t.json :pure_json_data
|
|
11
23
|
t.json :data
|
|
12
24
|
else
|
|
13
25
|
t.text :data
|
|
@@ -20,6 +32,7 @@ ActiveRecord::Schema.define do
|
|
|
20
32
|
end
|
|
21
33
|
|
|
22
34
|
if t.respond_to?(:jsonb)
|
|
35
|
+
t.jsonb :pure_jsonb_data
|
|
23
36
|
t.jsonb :settings
|
|
24
37
|
t.jsonb :json_data, null: false, default: {}
|
|
25
38
|
else
|
|
@@ -27,6 +40,8 @@ ActiveRecord::Schema.define do
|
|
|
27
40
|
t.text :json_data
|
|
28
41
|
end
|
|
29
42
|
|
|
43
|
+
t.column :vendor_type, :vendor_type
|
|
44
|
+
|
|
30
45
|
t.datetime :created_at
|
|
31
46
|
t.datetime :updated_at
|
|
32
47
|
end
|
|
@@ -42,4 +57,38 @@ ActiveRecord::Schema.define do
|
|
|
42
57
|
end
|
|
43
58
|
|
|
44
59
|
add_index :alarms, [:device_id, :alarm_type], unique: true, where: 'status <> 0'
|
|
60
|
+
|
|
61
|
+
unless ENV["SKIP_COMPOSITE_PK"]
|
|
62
|
+
create_table :authors, force: :cascade do |t|
|
|
63
|
+
t.string :name
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
execute %(
|
|
67
|
+
DROP SEQUENCE IF EXISTS composite_book_id_seq CASCADE;
|
|
68
|
+
CREATE SEQUENCE composite_book_id_seq
|
|
69
|
+
AS integer
|
|
70
|
+
START WITH 1
|
|
71
|
+
INCREMENT BY 1
|
|
72
|
+
NO MINVALUE
|
|
73
|
+
NO MAXVALUE
|
|
74
|
+
CACHE 1;
|
|
75
|
+
|
|
76
|
+
DROP TABLE IF EXISTS composite_books;
|
|
77
|
+
CREATE TABLE composite_books (
|
|
78
|
+
id bigint DEFAULT nextval('composite_book_id_seq'::regclass) NOT NULL,
|
|
79
|
+
title character varying,
|
|
80
|
+
author_id bigint
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
ALTER TABLE ONLY composite_books ADD CONSTRAINT fk_rails_040a418131 FOREIGN KEY (author_id) REFERENCES authors(id);
|
|
84
|
+
).split.join(' ').strip
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
create_table :composite_chapters, force: :cascade do |t|
|
|
88
|
+
t.string :title
|
|
89
|
+
t.integer :composite_book_id, null: false
|
|
90
|
+
t.integer :author_id, null: false
|
|
91
|
+
t.datetime :created_at
|
|
92
|
+
t.datetime :updated_at
|
|
93
|
+
end
|
|
45
94
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
ActiveRecord::Schema.define do
|
|
4
|
+
create_table :alarms, force: true do |t|
|
|
5
|
+
t.column :device_id, :integer, null: false
|
|
6
|
+
t.column :alarm_type, :integer, null: false
|
|
7
|
+
t.column :status, :integer, null: false
|
|
8
|
+
t.column :metadata, :text
|
|
9
|
+
t.column :secret_key, :binary
|
|
10
|
+
t.datetime :created_at
|
|
11
|
+
t.datetime :updated_at
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
add_index :alarms, [:device_id, :alarm_type], unique: true, where: 'status <> 0'
|
|
15
|
+
end
|
data/test/schema/version.rb
CHANGED
data/test/sqlite3/import_test.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../support/sqlite3/import_examples")
|
|
3
5
|
|
|
4
6
|
should_support_sqlite3_import_functionality
|
data/test/support/assertions.rb
CHANGED
data/test/support/factories.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
FactoryBot.define do
|
|
2
4
|
sequence(:book_title) { |n| "Book #{n}" }
|
|
3
5
|
sequence(:chapter_title) { |n| "Chapter #{n}" }
|
|
4
6
|
sequence(:end_note) { |n| "Endnote #{n}" }
|
|
@@ -9,7 +11,7 @@ FactoryGirl.define do
|
|
|
9
11
|
|
|
10
12
|
factory :invalid_topic, class: "Topic" do
|
|
11
13
|
sequence(:title) { |n| "Title #{n}" }
|
|
12
|
-
author_name nil
|
|
14
|
+
author_name { nil }
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
factory :topic do
|
|
@@ -27,7 +29,7 @@ FactoryGirl.define do
|
|
|
27
29
|
|
|
28
30
|
trait :with_rule do
|
|
29
31
|
after(:build) do |question|
|
|
30
|
-
question.build_rule(
|
|
32
|
+
question.build_rule(FactoryBot.attributes_for(:rule))
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
end
|
|
@@ -40,21 +42,21 @@ FactoryGirl.define do
|
|
|
40
42
|
factory :topic_with_book, parent: :topic do
|
|
41
43
|
after(:build) do |topic|
|
|
42
44
|
2.times do
|
|
43
|
-
book = topic.books.build(title:
|
|
45
|
+
book = topic.books.build(title: FactoryBot.generate(:book_title), author_name: 'Stephen King')
|
|
44
46
|
3.times do
|
|
45
|
-
book.chapters.build(title:
|
|
47
|
+
book.chapters.build(title: FactoryBot.generate(:chapter_title))
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
4.times do
|
|
49
|
-
book.end_notes.build(note:
|
|
51
|
+
book.end_notes.build(note: FactoryBot.generate(:end_note))
|
|
50
52
|
end
|
|
51
53
|
end
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
factory :book do
|
|
56
|
-
title 'Tortilla Flat'
|
|
57
|
-
author_name 'John Steinbeck'
|
|
58
|
+
title { 'Tortilla Flat' }
|
|
59
|
+
author_name { 'John Steinbeck' }
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
factory :car do
|
data/test/support/generate.rb
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ActiveSupport::TestCase
|
|
2
|
-
def Build(*args) # rubocop:disable
|
|
4
|
+
def Build(*args) # rubocop:disable Naming/MethodName
|
|
3
5
|
n = args.shift if args.first.is_a?(Numeric)
|
|
4
6
|
factory = args.shift
|
|
5
|
-
|
|
7
|
+
factory_bot_args = args.shift || {}
|
|
6
8
|
|
|
7
9
|
if n
|
|
8
10
|
[].tap do |collection|
|
|
9
|
-
n.times.each { collection <<
|
|
11
|
+
n.times.each { collection << FactoryBot.build(factory.to_s.singularize.to_sym, factory_bot_args) }
|
|
10
12
|
end
|
|
11
13
|
else
|
|
12
|
-
|
|
14
|
+
FactoryBot.build(factory.to_s.singularize.to_sym, factory_bot_args)
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
def Generate(*args) # rubocop:disable
|
|
18
|
+
def Generate(*args) # rubocop:disable Naming/MethodName
|
|
17
19
|
n = args.shift if args.first.is_a?(Numeric)
|
|
18
20
|
factory = args.shift
|
|
19
|
-
|
|
21
|
+
factory_bot_args = args.shift || {}
|
|
20
22
|
|
|
21
23
|
if n
|
|
22
24
|
[].tap do |collection|
|
|
23
|
-
n.times.each { collection <<
|
|
25
|
+
n.times.each { collection << FactoryBot.create(factory.to_s.singularize.to_sym, factory_bot_args) }
|
|
24
26
|
end
|
|
25
27
|
else
|
|
26
|
-
|
|
28
|
+
FactoryBot.create(factory.to_s.singularize.to_sym, factory_bot_args)
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
end
|