to_factory 2.0.0 → 3.0.0.pre.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +35 -0
- data/.gitignore +1 -0
- data/.rubocop-disabled.yml +95 -0
- data/.rubocop-enabled.yml +1194 -0
- data/.rubocop.yml +938 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +6 -1
- data/README.md +11 -10
- data/Rakefile +17 -9
- data/lib/to_factory/collation.rb +9 -9
- data/lib/to_factory/file_sync.rb +11 -11
- data/lib/to_factory/file_writer.rb +18 -2
- data/lib/to_factory/finders/factory.rb +8 -2
- data/lib/to_factory/finders/model.rb +11 -13
- data/lib/to_factory/generation/attribute.rb +10 -12
- data/lib/to_factory/generation/factory.rb +3 -3
- data/lib/to_factory/klass_inference.rb +4 -6
- data/lib/to_factory/options_parser.rb +4 -4
- data/lib/to_factory/parsing/file.rb +87 -14
- data/lib/to_factory/representation.rb +9 -6
- data/lib/to_factory/version.rb +1 -1
- data/lib/to_factory.rb +7 -17
- data/spec/db/migrate/1_create_users.rb +4 -4
- data/spec/db/migrate/2_create_projects.rb +4 -4
- data/spec/db/migrate/3_create_not_namespaced.rb +4 -4
- data/spec/db/migrate/4_add_birthday_to_users.rb +3 -3
- data/spec/db/migrate/5_add_serialized_attributes_to_users.rb +3 -3
- data/spec/example_factories/admin.rb +6 -6
- data/spec/example_factories/admin_with_header.rb +7 -7
- data/spec/example_factories/inherited_project_with_header.rb +7 -0
- data/spec/example_factories/project_with_header.rb +4 -4
- data/spec/example_factories/user.rb +5 -5
- data/spec/example_factories/user_admin.rb +11 -11
- data/spec/example_factories/user_admin_root.rb +12 -12
- data/spec/example_factories/user_admin_super_admin.rb +6 -6
- data/spec/example_factories/user_admin_with_header.rb +12 -12
- data/spec/example_factories/user_with_header.rb +6 -6
- data/spec/integration/empty_factory_file_spec.rb +19 -0
- data/spec/integration/file_sync_spec.rb +16 -24
- data/spec/integration/file_writer_spec.rb +13 -9
- data/spec/integration/lint_spec.rb +4 -3
- data/spec/integration/multiple_to_factory_calls_spec.rb +96 -0
- data/spec/integration/non_active_record_classes_spec.rb +40 -0
- data/spec/integration/to_factory_method_spec.rb +21 -20
- data/spec/spec_helper.rb +9 -18
- data/spec/support/broken_models/invalid_ruby_file.rb +1 -0
- data/spec/support/broken_models/project.rb +3 -0
- data/spec/support/data_creation.rb +11 -13
- data/spec/support/match_sexp.rb +0 -1
- data/spec/support/non_active_record/inherited_project.rb +3 -0
- data/spec/support/non_active_record/project.rb +3 -0
- data/spec/support/non_active_record/some_other_service_inheriting_from_something_else.rb +4 -0
- data/spec/support/non_active_record/some_service.rb +2 -0
- data/spec/support/non_active_record/something_else.rb +2 -0
- data/spec/support/ruby_parser_exception_causing_string.rb +29 -29
- data/spec/unit/collation_spec.rb +9 -10
- data/spec/unit/file_writer_spec.rb +4 -8
- data/spec/unit/finders/factory_spec.rb +7 -9
- data/spec/unit/finders/model_spec.rb +35 -8
- data/spec/unit/generation/attribute_spec.rb +22 -22
- data/spec/unit/generation/factory_spec.rb +38 -14
- data/spec/unit/parsing/file_spec.rb +9 -9
- data/spec/unit/parsing/klass_inference_spec.rb +5 -7
- data/to_factory.gemspec +17 -15
- metadata +109 -44
- data/.travis.yml +0 -14
- data/lib/to_factory/parsing/syntax.rb +0 -83
@@ -1,13 +1,13 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
2
|
-
def
|
1
|
+
class CreateUsers < ActiveRecord::Migration[6.1]
|
2
|
+
def up
|
3
3
|
create_table :users do |t|
|
4
|
-
t.column :name, :string, :
|
4
|
+
t.column :name, :string, null: false
|
5
5
|
t.column :email, :string
|
6
6
|
t.integer :some_id
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def down
|
11
11
|
drop_table :users
|
12
12
|
end
|
13
13
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
class CreateProjects < ActiveRecord::Migration
|
2
|
-
def
|
1
|
+
class CreateProjects < ActiveRecord::Migration[6.1]
|
2
|
+
def up
|
3
3
|
create_table :projects do |t|
|
4
|
-
t.column :name, :string, :
|
4
|
+
t.column :name, :string, null: false
|
5
5
|
t.column :objective, :string
|
6
6
|
t.integer :some_id
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def down
|
11
11
|
drop_table :projects
|
12
12
|
end
|
13
13
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateNotNamespaced < ActiveRecord::Migration
|
2
|
-
def
|
1
|
+
class CreateNotNamespaced < ActiveRecord::Migration[6.1]
|
2
|
+
def up
|
3
3
|
create_table :not_namespaced_active_record_class_but_long_enough_it_shouldnt_cause_conflicts do |t|
|
4
|
-
t.column :name, :string, :
|
4
|
+
t.column :name, :string, null: false
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def down
|
9
9
|
drop_table :not_namespaced_active_record_class_but_long_enough_it_shouldnt_cause_conflicts
|
10
10
|
end
|
11
11
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class AddSerializedAttributesToUsers < ActiveRecord::Migration
|
2
|
-
def
|
1
|
+
class AddSerializedAttributesToUsers < ActiveRecord::Migration[6.1]
|
2
|
+
def up
|
3
3
|
add_column :users, :some_attributes, :text
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
6
|
+
def down
|
7
7
|
remove_column :users, :some_attributes
|
8
8
|
end
|
9
9
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
factory(:admin, :
|
2
|
-
birthday "2014-07-08T15:30 UTC"
|
3
|
-
email "admin@example.com"
|
4
|
-
name "Admin"
|
5
|
-
some_attributes
|
6
|
-
some_id 9
|
1
|
+
factory(:admin, parent: :"to_factory/user") do
|
2
|
+
birthday { "2014-07-08T15:30 UTC" }
|
3
|
+
email {"admin@example.com"}
|
4
|
+
name {"Admin"}
|
5
|
+
some_attributes {{a: 1}}
|
6
|
+
some_id { 9 }
|
7
7
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
factory(:admin, :
|
3
|
-
birthday "2014-07-08T15:30 UTC"
|
4
|
-
email "admin@example.com"
|
5
|
-
name "Admin"
|
6
|
-
some_attributes
|
7
|
-
some_id 9
|
1
|
+
FactoryBot.define do
|
2
|
+
factory(:admin, parent: :"to_factory/user") do
|
3
|
+
birthday { "2014-07-08T15:30 UTC" }
|
4
|
+
email { "admin@example.com" }
|
5
|
+
name {"Admin" }
|
6
|
+
some_attributes { {a: 1 } }
|
7
|
+
some_id { 9 }
|
8
8
|
end
|
9
9
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
factory(:"to_factory/user") do
|
2
|
-
birthday "2014-07-08T15:30 UTC"
|
3
|
-
email "test@example.com"
|
4
|
-
name "Jeff"
|
5
|
-
some_attributes
|
6
|
-
some_id 8
|
2
|
+
birthday {"2014-07-08T15:30 UTC"}
|
3
|
+
email {"test@example.com"}
|
4
|
+
name {"Jeff"}
|
5
|
+
some_attributes {{a: 1}}
|
6
|
+
some_id { 8 }
|
7
7
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
factory(:"to_factory/user") do
|
2
|
-
birthday "2014-07-08T15:30 UTC"
|
3
|
-
email "test@example.com"
|
4
|
-
name "Jeff"
|
5
|
-
some_attributes
|
6
|
-
some_id 8
|
2
|
+
birthday { "2014-07-08T15:30 UTC" }
|
3
|
+
email { "test@example.com" }
|
4
|
+
name { "Jeff" }
|
5
|
+
some_attributes { {a: 1 } }
|
6
|
+
some_id { 8 }
|
7
7
|
end
|
8
8
|
|
9
|
-
factory(:admin, :
|
10
|
-
birthday "2014-07-08T15:30 UTC"
|
11
|
-
email "admin@example.com"
|
12
|
-
name "Admin"
|
13
|
-
some_attributes
|
14
|
-
some_id 9
|
9
|
+
factory(:admin, parent: :"to_factory/user") do
|
10
|
+
birthday {"2014-07-08T15:30 UTC"}
|
11
|
+
email {"admin@example.com"}
|
12
|
+
name {"Admin"}
|
13
|
+
some_attributes { {a: 1 } }
|
14
|
+
some_id { 9 }
|
15
15
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory(:"to_factory/user") do
|
3
|
-
name
|
3
|
+
name {"User"}
|
4
4
|
end
|
5
5
|
|
6
|
-
factory(:
|
7
|
-
|
8
|
-
email "test@example.com"
|
9
|
-
name "Jeff"
|
10
|
-
some_attributes({:a => 1})
|
11
|
-
some_id 8
|
6
|
+
factory(:admin, parent: :"to_factory/user") do
|
7
|
+
name {"Admin"}
|
12
8
|
end
|
13
9
|
|
14
|
-
factory(:
|
15
|
-
|
10
|
+
factory(:root, parent: :"to_factory/user") do
|
11
|
+
birthday {"2014-07-08T15:30 UTC"}
|
12
|
+
email {"test@example.com"}
|
13
|
+
name {"Jeff"}
|
14
|
+
some_attributes {{a: 1}}
|
15
|
+
some_id { 8 }
|
16
16
|
end
|
17
17
|
|
18
|
-
factory(:super_admin, :
|
19
|
-
name
|
18
|
+
factory(:super_admin, parent: :admin) do
|
19
|
+
name {"Super Admin"}
|
20
20
|
end
|
21
21
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory(:"to_factory/user") do
|
3
|
-
name "User"
|
3
|
+
name {"User"}
|
4
4
|
end
|
5
5
|
|
6
|
-
factory(:admin, :
|
7
|
-
name "Admin"
|
6
|
+
factory(:admin, parent: :"to_factory/user") do
|
7
|
+
name {"Admin" }
|
8
8
|
end
|
9
9
|
|
10
|
-
factory(:super_admin, :
|
11
|
-
name "Super Admin"
|
10
|
+
factory(:super_admin, parent: :admin) do
|
11
|
+
name {"Super Admin"}
|
12
12
|
end
|
13
13
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory(:"to_factory/user") do
|
3
|
-
birthday "2014-07-08T15:30 UTC"
|
4
|
-
email "test@example.com"
|
5
|
-
name "Jeff"
|
6
|
-
some_attributes
|
7
|
-
some_id 8
|
3
|
+
birthday {"2014-07-08T15:30 UTC"}
|
4
|
+
email {"test@example.com"}
|
5
|
+
name {"Jeff"}
|
6
|
+
some_attributes {{a: 1}}
|
7
|
+
some_id { 8 }
|
8
8
|
end
|
9
9
|
|
10
|
-
factory(:admin, :
|
11
|
-
birthday "2014-07-08T15:30 UTC"
|
12
|
-
email "admin@example.com"
|
13
|
-
name "Admin"
|
14
|
-
some_attributes
|
15
|
-
some_id 9
|
10
|
+
factory(:admin, parent: :"to_factory/user") do
|
11
|
+
birthday {"2014-07-08T15:30 UTC"}
|
12
|
+
email {"admin@example.com"}
|
13
|
+
name {"Admin"}
|
14
|
+
some_attributes {{a: 1}}
|
15
|
+
some_id { 9 }
|
16
16
|
end
|
17
17
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory(:"to_factory/user") do
|
3
|
-
birthday "2014-07-08T15:30 UTC"
|
4
|
-
email "test@example.com"
|
5
|
-
name "Jeff"
|
6
|
-
some_attributes
|
7
|
-
some_id 8
|
3
|
+
birthday { "2014-07-08T15:30 UTC" }
|
4
|
+
email { "test@example.com" }
|
5
|
+
name { "Jeff" }
|
6
|
+
some_attributes { {:a => 1} }
|
7
|
+
some_id { 8 }
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "Empty File spec" do
|
2
|
+
let(:user) { create_user! }
|
3
|
+
|
4
|
+
context "with an empty factory file" do
|
5
|
+
before do
|
6
|
+
user
|
7
|
+
FileUtils.mkdir_p "./tmp/factories/to_factory"
|
8
|
+
|
9
|
+
File.open("./tmp/factories/to_factory/empty.rb", "w") do |f|
|
10
|
+
f << " "
|
11
|
+
f << "\n "
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "doesn't blow up" do
|
16
|
+
ToFactory(empty: OpenStruct.new({ attributes: {} }), user: user)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,28 +1,25 @@
|
|
1
1
|
describe "FileSync" do
|
2
|
-
let(:user) { create_user!
|
3
|
-
let(:admin) { create_admin!
|
4
|
-
let(:project) { create_project!
|
5
|
-
let(:version) { "new" }
|
2
|
+
let(:user) { create_user! }
|
3
|
+
let(:admin) { create_admin! }
|
4
|
+
let(:project) { create_project! }
|
6
5
|
let(:expected_user_file) { File.read("./spec/example_factories/user.rb") }
|
7
6
|
let(:expected_user_with_header_file) { File.read("./spec/example_factories/user_with_header.rb") }
|
8
7
|
let(:expected_admin_file) { File.read("./spec/example_factories/admin.rb") }
|
9
8
|
let(:user_with_header) { File.read("./spec/example_factories/user_with_header.rb") }
|
10
9
|
let(:user_admin_with_header) { File.read("./spec/example_factories/user_admin_with_header.rb") }
|
11
10
|
|
12
|
-
|
13
|
-
before do
|
14
|
-
FileUtils.rm_rf "./tmp/factories"
|
15
|
-
end
|
16
|
-
|
17
11
|
def user_file
|
18
|
-
File.read("./tmp/factories/to_factory/user.rb")
|
12
|
+
File.read("./tmp/factories/to_factory/user.rb")
|
13
|
+
rescue
|
14
|
+
nil
|
19
15
|
end
|
20
16
|
|
21
17
|
def project_file
|
22
|
-
File.read("./tmp/factories/to_factory/project.rb")
|
18
|
+
File.read("./tmp/factories/to_factory/project.rb")
|
19
|
+
rescue
|
20
|
+
nil
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
23
|
context "with no arguments" do
|
27
24
|
before do
|
28
25
|
user
|
@@ -33,7 +30,7 @@ describe "FileSync" do
|
|
33
30
|
sync = ToFactory::FileSync.new
|
34
31
|
sync.perform
|
35
32
|
|
36
|
-
expect(user_file
|
33
|
+
expect(user_file).to match_sexp expected_user_with_header_file
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -42,13 +39,11 @@ describe "FileSync" do
|
|
42
39
|
sync = ToFactory::FileSync.new(user)
|
43
40
|
sync.perform
|
44
41
|
|
45
|
-
expect(user_file
|
42
|
+
expect(user_file).to match_sexp user_with_header
|
46
43
|
expect(project_file).to eq nil
|
47
44
|
end
|
48
45
|
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
47
|
context "with a pre-existing file" do
|
53
48
|
let(:sync) { ToFactory::FileSync.new(user) }
|
54
49
|
before do
|
@@ -57,26 +52,23 @@ describe "FileSync" do
|
|
57
52
|
end
|
58
53
|
|
59
54
|
it "raises an error" do
|
60
|
-
expect
|
55
|
+
expect { sync.perform }.to raise_error ToFactory::AlreadyExists
|
61
56
|
end
|
62
57
|
|
63
58
|
context "with a named factory" do
|
64
59
|
it do
|
65
|
-
sync = ToFactory::FileSync.new(
|
60
|
+
sync = ToFactory::FileSync.new(admin: admin)
|
66
61
|
sync.perform
|
67
62
|
|
68
63
|
parser = ToFactory::Parsing::File.new(user_file)
|
69
64
|
result = parser.parse
|
70
|
-
admin= result.find{|r| r.name == "admin"}
|
71
|
-
user= result.find{|r| r.name == "to_factory/user"}
|
72
|
-
|
65
|
+
admin = result.find { |r| r.name == "admin" }
|
66
|
+
user = result.find { |r| r.name == "to_factory/user" }
|
73
67
|
|
74
68
|
expect(admin.definition).to match_sexp expected_admin_file
|
75
69
|
expect(user.definition).to match_sexp expected_user_file
|
76
70
|
|
77
|
-
expect
|
78
|
-
sync.perform
|
79
|
-
}).to raise_error ToFactory::AlreadyExists
|
71
|
+
expect { sync.perform }.to raise_error ToFactory::AlreadyExists
|
80
72
|
end
|
81
73
|
end
|
82
74
|
end
|
@@ -1,18 +1,22 @@
|
|
1
1
|
describe ToFactory::FileWriter do
|
2
|
-
let(:
|
3
|
-
let(:
|
4
|
-
let(:user_file_contents) { File.read "./tmp/factories/to_factory/user.rb"}
|
2
|
+
let(:file_writer) { ToFactory::FileWriter.new }
|
3
|
+
let(:user_file_contents) { File.read "./tmp/factories/to_factory/user.rb" }
|
5
4
|
let!(:user) { create_user! }
|
6
|
-
let!(:admin) { create_admin!
|
5
|
+
let!(:admin) { create_admin! }
|
6
|
+
let(:file_sync) { ToFactory::FileSync.new }
|
7
|
+
let(:representations) { file_sync.all_representations }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#sanity check generation isn't broken
|
9
|
+
let(:expected) { File.read "./spec/example_factories/user_with_header.rb" }
|
10
|
+
|
11
|
+
before do
|
12
|
+
# sanity check generation isn't broken
|
12
13
|
expect(representations.keys).to eq ["to_factory/user"]
|
13
14
|
expect(representations.values[0][0]).to be_a ToFactory::Representation
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'writes correctly' do
|
18
|
+
file_writer.write representations
|
14
19
|
|
15
|
-
fw.write representations
|
16
20
|
expect(user_file_contents).to match_sexp expected
|
17
21
|
end
|
18
22
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
context "full integration" do
|
2
2
|
let(:user) do
|
3
|
-
ToFactory::User.create :
|
3
|
+
ToFactory::User.create name: "Jeff", email: "test@example.com", some_id: 8, birthday: Time.now
|
4
4
|
end
|
5
5
|
|
6
6
|
it "#to_factory linting the output" do
|
7
7
|
ToFactory(user)
|
8
|
+
require 'factory_bot'
|
9
|
+
|
8
10
|
load "./tmp/factories/to_factory/user.rb"
|
9
|
-
|
11
|
+
FactoryBot.lint
|
10
12
|
end
|
11
13
|
end
|
12
|
-
|
@@ -0,0 +1,96 @@
|
|
1
|
+
describe ToFactory do
|
2
|
+
let!(:user) { create_user! }
|
3
|
+
|
4
|
+
def user_file
|
5
|
+
File.read("./tmp/factories/to_factory/user.rb")
|
6
|
+
rescue
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb" }
|
11
|
+
|
12
|
+
context "single call" do
|
13
|
+
before do
|
14
|
+
ToFactory()
|
15
|
+
end
|
16
|
+
it "renders a single factory correctly" do
|
17
|
+
expect(user_file).to match_sexp expected_user_file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "two calls" do
|
22
|
+
before do
|
23
|
+
ToFactory()
|
24
|
+
ToFactory(user_2: ToFactory::User.first)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "renders two factories correctly" do
|
28
|
+
expect(user_file).to eq <<-FACTORY.strip_heredoc
|
29
|
+
FactoryBot.define do
|
30
|
+
factory(:"to_factory/user") do
|
31
|
+
birthday { "2014-07-08T15:30 UTC" }
|
32
|
+
email { "test@example.com" }
|
33
|
+
name { "Jeff" }
|
34
|
+
some_attributes { { :a => 1 } }
|
35
|
+
some_id { 8 }
|
36
|
+
end
|
37
|
+
|
38
|
+
factory(:user_2, :parent => :"to_factory/user") do
|
39
|
+
birthday { "2014-07-08T15:30 UTC" }
|
40
|
+
email { "test@example.com" }
|
41
|
+
name { "Jeff" }
|
42
|
+
some_attributes { {:a => 1} }
|
43
|
+
some_id { 8 }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
FACTORY
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "multiple calls" do
|
51
|
+
before do
|
52
|
+
ToFactory()
|
53
|
+
ToFactory(user_2: ToFactory::User.first)
|
54
|
+
ToFactory(user_3: ToFactory::User.first)
|
55
|
+
ToFactory(user_4: ToFactory::User.first)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "renders multiple factories correctly" do
|
59
|
+
expect(user_file).to match_sexp <<-FACTORY
|
60
|
+
FactoryBot.define do
|
61
|
+
factory(:"to_factory/user") do
|
62
|
+
birthday { "2014-07-08T15:30 UTC" }
|
63
|
+
email { "test@example.com" }
|
64
|
+
name { "Jeff" }
|
65
|
+
some_attributes { {:a => 1} }
|
66
|
+
some_id { 8 }
|
67
|
+
end
|
68
|
+
|
69
|
+
factory(:user_2, :parent => :"to_factory/user") do
|
70
|
+
birthday { "2014-07-08T15:30 UTC" }
|
71
|
+
email { "test@example.com" }
|
72
|
+
name { "Jeff" }
|
73
|
+
some_attributes { {:a => 1} }
|
74
|
+
some_id { 8 }
|
75
|
+
end
|
76
|
+
|
77
|
+
factory(:user_3, :parent => :"to_factory/user") do
|
78
|
+
birthday { "2014-07-08T15:30 UTC" }
|
79
|
+
email { "test@example.com" }
|
80
|
+
name { "Jeff" }
|
81
|
+
some_attributes { {:a => 1} }
|
82
|
+
some_id { 8 }
|
83
|
+
end
|
84
|
+
|
85
|
+
factory(:user_4, :parent => :"to_factory/user") do
|
86
|
+
birthday { "2014-07-08T15:30 UTC" }
|
87
|
+
email { "test@example.com" }
|
88
|
+
name { "Jeff" }
|
89
|
+
some_attributes { {:a => 1} }
|
90
|
+
some_id { 8 }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
FACTORY
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
describe "non active record classes" do
|
2
|
+
let!(:project) { create_project! }
|
3
|
+
|
4
|
+
def project_file
|
5
|
+
File.read("./tmp/factories/to_factory/project.rb")
|
6
|
+
rescue
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def inherited_project_file
|
11
|
+
File.read("./tmp/factories/to_factory/inherited_project.rb")
|
12
|
+
rescue
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:expected_project_file) { File.read "./spec/example_factories/project_with_header.rb" }
|
17
|
+
let(:expected_inherited_project_file) { File.read "./spec/example_factories/inherited_project_with_header.rb" }
|
18
|
+
|
19
|
+
context "given a folder with non active record models in" do
|
20
|
+
before do
|
21
|
+
ToFactory.models = "./spec/support/non_active_record"
|
22
|
+
ToFactory()
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates an ordinary factory correctly" do
|
26
|
+
expect(project_file).to match_sexp expected_project_file
|
27
|
+
end
|
28
|
+
|
29
|
+
context "STI" do
|
30
|
+
it "creates a single factory correctly" do
|
31
|
+
expect(inherited_project_file).to match_sexp expected_inherited_project_file
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "doesn't create other factories" do
|
36
|
+
count = Dir.glob("./tmp/factories/*.rb").length
|
37
|
+
expect(count).to eq 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|