to_factory 0.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -9
- data/Gemfile +2 -3
- data/lib/to_factory/file_writer.rb +0 -8
- data/lib/to_factory/generation/attribute.rb +7 -13
- data/lib/to_factory/generation/factory.rb +5 -9
- data/lib/to_factory/parsing/file.rb +2 -8
- data/lib/to_factory/parsing/ruby_parsing_helpers.rb +17 -0
- data/lib/to_factory/parsing/syntax.rb +34 -11
- data/lib/to_factory/representation.rb +21 -0
- data/lib/to_factory/version.rb +1 -1
- data/lib/to_factory.rb +2 -11
- data/spec/example_factories/{new_syntax/admin.rb → admin.rb} +1 -1
- data/spec/example_factories/{new_syntax/admin_with_header.rb → admin_with_header.rb} +1 -1
- data/spec/example_factories/{new_syntax/project_with_header.rb → project_with_header.rb} +0 -0
- data/spec/example_factories/{new_syntax/user.rb → user.rb} +1 -1
- data/spec/example_factories/{new_syntax/user_admin.rb → user_admin.rb} +2 -2
- data/spec/example_factories/{new_syntax/user_admin_root.rb → user_admin_root.rb} +1 -1
- data/spec/example_factories/{new_syntax/user_admin_super_admin.rb → user_admin_super_admin.rb} +0 -0
- data/spec/example_factories/{new_syntax/user_admin_with_header.rb → user_admin_with_header.rb} +2 -2
- data/spec/example_factories/{new_syntax/user_with_header.rb → user_with_header.rb} +1 -1
- data/spec/integration/file_sync_spec.rb +6 -6
- data/spec/integration/file_writer_spec.rb +1 -1
- data/spec/integration/lint_spec.rb +3 -7
- data/spec/integration/to_factory_method_spec.rb +7 -18
- data/spec/spec_helper.rb +0 -7
- data/spec/unit/file_writer_spec.rb +1 -3
- data/spec/unit/finders/factory_spec.rb +3 -3
- data/spec/unit/generation/attribute_spec.rb +18 -2
- data/spec/unit/generation/factory_spec.rb +64 -0
- data/spec/unit/parsing/file_spec.rb +31 -17
- data/to_factory.gemspec +5 -20
- metadata +49 -65
- data/lib/to_factory/parsing/new_syntax.rb +0 -19
- data/lib/to_factory/parsing/old_syntax.rb +0 -13
- data/spec/example_factories/old_syntax/admin.rb +0 -7
- data/spec/example_factories/old_syntax/project_with_header.rb +0 -5
- data/spec/example_factories/old_syntax/user.rb +0 -7
- data/spec/example_factories/old_syntax/user_admin.rb +0 -15
- data/spec/example_factories/old_syntax/user_admin_root.rb +0 -21
- data/spec/example_factories/old_syntax/user_admin_super_admin.rb +0 -12
- data/spec/example_factories/old_syntax/user_admin_with_header.rb +0 -15
- data/spec/example_factories/old_syntax/user_with_header.rb +0 -7
- data/spec/unit/generator_spec.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6906cfbba894ee5d9a25a7a8c30467c59c0c7c27
|
4
|
+
data.tar.gz: 5a27e0c0912602908f81bd19335c46b880adbe77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac378d94509e96ea3417a714e6b4073033552fe675e43b263d020a577c9c2201f119ef23fe13563221a5a67d098bcca34f900f305117485980b3394faaa5c654
|
7
|
+
data.tar.gz: d19f74bdd1789ebf9d57c0fc267c39e5c9db3221828c9adec12d4dbc6002ea0ef11818e9c2009ee0d4943ebb142f332553a8c4c752d139ce4947e15fcb2c7df7
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -23,14 +23,6 @@ module ToFactory
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def wrap_factories(definitions)
|
26
|
-
if ToFactory.new_syntax?
|
27
|
-
modern_header(definitions)
|
28
|
-
else
|
29
|
-
definitions.join("\n\n")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def modern_header(definitions)
|
34
26
|
out = "FactoryGirl.define do\n"
|
35
27
|
out << definitions.join("\n\n")
|
36
28
|
out << "end"
|
@@ -8,12 +8,7 @@ module ToFactory
|
|
8
8
|
|
9
9
|
def to_s
|
10
10
|
setter = "#{@attribute}#{inspect_value(@value)}"
|
11
|
-
|
12
|
-
if ToFactory.new_syntax?
|
13
|
-
" #{setter}"
|
14
|
-
else
|
15
|
-
" o.#{setter}"
|
16
|
-
end
|
11
|
+
" #{setter}"
|
17
12
|
end
|
18
13
|
|
19
14
|
def inspect_value(value, nested=false)
|
@@ -26,10 +21,12 @@ module ToFactory
|
|
26
21
|
formatted
|
27
22
|
end
|
28
23
|
|
29
|
-
def format(value, nested)
|
24
|
+
def format(value, nested=false)
|
30
25
|
case value
|
31
26
|
when Time, DateTime
|
32
27
|
inspect_time(value)
|
28
|
+
when Date
|
29
|
+
value.to_s.inspect
|
33
30
|
when BigDecimal
|
34
31
|
value.to_f.inspect
|
35
32
|
when Hash
|
@@ -60,8 +57,9 @@ module ToFactory
|
|
60
57
|
end
|
61
58
|
|
62
59
|
def inspect_time(value)
|
63
|
-
|
64
|
-
|
60
|
+
value = value.strftime("%Y-%m-%dT%H:%M %Z").inspect
|
61
|
+
value.gsub! /GMT/, "UTC"
|
62
|
+
value
|
65
63
|
end
|
66
64
|
|
67
65
|
def inspect_hash(value, nested)
|
@@ -86,10 +84,6 @@ module ToFactory
|
|
86
84
|
formatted_value = inspect_value(value.fetch(key), true)
|
87
85
|
"#{formatted_key} => #{formatted_value}"
|
88
86
|
end
|
89
|
-
|
90
|
-
def in_utc(time)
|
91
|
-
time.utc
|
92
|
-
end
|
93
87
|
end
|
94
88
|
end
|
95
89
|
end
|
@@ -18,25 +18,21 @@ module ToFactory
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def header(&block)
|
21
|
-
|
22
|
-
generic_header(" factory", "", " end", &block)
|
23
|
-
else
|
24
|
-
generic_header("Factory.define", " |o|", "end", &block)
|
25
|
-
end
|
21
|
+
generic_header(" factory", "", " end", &block)
|
26
22
|
end
|
27
23
|
|
28
24
|
def factory_attribute(attr, value)
|
29
25
|
Attribute.new(attr, value).to_s
|
30
26
|
end
|
31
27
|
|
32
|
-
private
|
33
|
-
|
34
28
|
def attributes
|
35
|
-
to_skip = [:id, :created_at, :updated_at]
|
29
|
+
to_skip = [:id, :created_at, :created_on, :updated_at, :updated_on]
|
36
30
|
|
37
|
-
@representation.attributes.delete_if{|key, _| to_skip.include?
|
31
|
+
@representation.attributes.delete_if{|key, _| key.nil? || to_skip.include?(key.to_sym)}
|
38
32
|
end
|
39
33
|
|
34
|
+
private
|
35
|
+
|
40
36
|
def parent_name
|
41
37
|
@representation.parent_name
|
42
38
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'ruby2ruby'
|
2
2
|
require 'ruby_parser'
|
3
|
+
require "to_factory/parsing/ruby_parsing_helpers"
|
3
4
|
require 'to_factory/parsing/syntax'
|
4
|
-
require 'to_factory/parsing/new_syntax'
|
5
|
-
require 'to_factory/parsing/old_syntax'
|
6
5
|
|
7
6
|
module ToFactory
|
8
7
|
module Parsing
|
@@ -26,14 +25,9 @@ module ToFactory
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def parser
|
29
|
-
@parser ||=
|
28
|
+
@parser ||= Syntax.new(@contents)
|
30
29
|
end
|
31
30
|
|
32
|
-
private
|
33
|
-
|
34
|
-
def parser_klass
|
35
|
-
ToFactory.new_syntax? ? NewSyntax : OldSyntax
|
36
|
-
end
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ToFactory
|
2
|
+
module Parsing
|
3
|
+
module RubyParsingHelpers
|
4
|
+
def to_ruby(sexp)
|
5
|
+
ruby2ruby.process sexp.deep_clone
|
6
|
+
end
|
7
|
+
|
8
|
+
def ruby2ruby
|
9
|
+
@ruby2ruby ||= Ruby2Ruby.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def ruby_parser
|
13
|
+
@ruby_parseer ||= RubyParser.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,7 +2,16 @@ module ToFactory
|
|
2
2
|
module Parsing
|
3
3
|
ParseException = Class.new ::Exception
|
4
4
|
|
5
|
+
class CouldNotInferClassException < ::Exception
|
6
|
+
attr_reader :sexp
|
7
|
+
|
8
|
+
def initialize(sexp)
|
9
|
+
@sexp = sexp
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
class Syntax
|
14
|
+
include Parsing::RubyParsingHelpers
|
6
15
|
attr_accessor :contents
|
7
16
|
|
8
17
|
def initialize(contents)
|
@@ -15,13 +24,22 @@ module ToFactory
|
|
15
24
|
|
16
25
|
def parse
|
17
26
|
factories.map do |x|
|
18
|
-
|
27
|
+
representation_from(x)
|
19
28
|
end
|
20
29
|
|
21
30
|
rescue Racc::ParseError, StringScanner::Error => e
|
22
31
|
raise ParseException.new("Original exception: #{e.message}\n #{e.backtrace}\nToFactory Error parsing \n#{@contents}\n o")
|
23
32
|
end
|
24
33
|
|
34
|
+
|
35
|
+
def representation_from(x)
|
36
|
+
Representation.new(name_from(x), parent_from(x), to_ruby(x))
|
37
|
+
rescue CouldNotInferClassException => e
|
38
|
+
ruby = to_ruby(e.sexp)
|
39
|
+
Kernel.warn "ToFactory could not parse\n#{ruby}"
|
40
|
+
NullRepresentation.new(e.sexp)
|
41
|
+
end
|
42
|
+
|
25
43
|
def factories
|
26
44
|
if multiple_factories?
|
27
45
|
factories_sexp[1..-1]
|
@@ -36,25 +54,30 @@ module ToFactory
|
|
36
54
|
|
37
55
|
def name_from(sexp)
|
38
56
|
sexp[1][3][1]
|
57
|
+
rescue NoMethodError
|
58
|
+
raise CouldNotInferClassException.new(sexp)
|
39
59
|
end
|
40
60
|
|
41
|
-
|
61
|
+
def header?
|
62
|
+
sexp[1][1][1] == :FactoryGirl rescue false
|
63
|
+
end
|
42
64
|
|
43
|
-
def
|
44
|
-
|
65
|
+
def parent_from(x)
|
66
|
+
# e.g.
|
67
|
+
#s(:call, nil, :factory, s(:lit, :admin), s(:hash, s(:lit, :parent), s(:lit, :"to_factory/user")))
|
68
|
+
x[1][4][2][1]
|
69
|
+
rescue NoMethodError
|
70
|
+
# e.g.
|
71
|
+
#s(:call, nil, :factory, s(:lit, :"to_factory/user"))
|
72
|
+
x[1][3][1]
|
45
73
|
end
|
46
74
|
|
75
|
+
private
|
76
|
+
|
47
77
|
def sexp
|
48
78
|
@sexp ||= ruby_parser.process(@contents)
|
49
79
|
end
|
50
80
|
|
51
|
-
def ruby2ruby
|
52
|
-
@ruby2ruby ||= Ruby2Ruby.new
|
53
|
-
end
|
54
|
-
|
55
|
-
def ruby_parser
|
56
|
-
@ruby_parseer ||= RubyParser.new
|
57
|
-
end
|
58
81
|
end
|
59
82
|
end
|
60
83
|
end
|
@@ -1,4 +1,25 @@
|
|
1
1
|
module ToFactory
|
2
|
+
class NullRepresentation
|
3
|
+
include ToFactory::Parsing::RubyParsingHelpers
|
4
|
+
|
5
|
+
def initialize(sexp)
|
6
|
+
@sexp = sexp
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def parent
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def definition
|
18
|
+
to_ruby(@sexp)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
2
23
|
class Representation
|
3
24
|
delegate :attributes, :to => :record
|
4
25
|
attr_accessor :klass, :name, :parent_name, :definition, :hierarchy_order, :record
|
data/lib/to_factory/version.rb
CHANGED
data/lib/to_factory.rb
CHANGED
@@ -8,27 +8,18 @@ require "to_factory/collation"
|
|
8
8
|
require "to_factory/file_writer"
|
9
9
|
require "to_factory/finders/model"
|
10
10
|
require "to_factory/finders/factory"
|
11
|
-
require "to_factory/representation"
|
12
11
|
require "to_factory/file_sync"
|
13
12
|
require "to_factory/parsing/file"
|
13
|
+
require "to_factory/representation"
|
14
14
|
require "to_factory/klass_inference"
|
15
15
|
require "to_factory/options_parser"
|
16
|
+
require "factory_girl"
|
16
17
|
|
17
18
|
module ToFactory
|
18
19
|
class MissingActiveRecordInstanceException < Exception;end
|
19
20
|
class NotFoundError < Exception;end
|
20
21
|
|
21
22
|
class << self
|
22
|
-
def new_syntax?
|
23
|
-
require "factory_girl"
|
24
|
-
if FactoryGirl::VERSION.to_s[0..0].to_i > 1
|
25
|
-
true
|
26
|
-
else
|
27
|
-
false
|
28
|
-
end
|
29
|
-
rescue NameError, ArgumentError
|
30
|
-
false
|
31
|
-
end
|
32
23
|
|
33
24
|
def definition_for(item)
|
34
25
|
if item.is_a? ActiveRecord::Base
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
factory(:"to_factory/user") do
|
2
|
-
birthday "2014-07-08T15:
|
2
|
+
birthday "2014-07-08T15:30 UTC"
|
3
3
|
email "test@example.com"
|
4
4
|
name "Jeff"
|
5
5
|
some_attributes({:a => 1})
|
@@ -7,7 +7,7 @@ factory(:"to_factory/user") do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
factory(:admin, :parent => :"to_factory/user") do
|
10
|
-
birthday "2014-07-08T15:
|
10
|
+
birthday "2014-07-08T15:30 UTC"
|
11
11
|
email "admin@example.com"
|
12
12
|
name "Admin"
|
13
13
|
some_attributes({:a => 1})
|
data/spec/example_factories/{new_syntax/user_admin_super_admin.rb → user_admin_super_admin.rb}
RENAMED
File without changes
|
data/spec/example_factories/{new_syntax/user_admin_with_header.rb → user_admin_with_header.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
FactoryGirl.define do
|
2
2
|
factory(:"to_factory/user") do
|
3
|
-
birthday "2014-07-08T15:
|
3
|
+
birthday "2014-07-08T15:30 UTC"
|
4
4
|
email "test@example.com"
|
5
5
|
name "Jeff"
|
6
6
|
some_attributes({:a => 1})
|
@@ -8,7 +8,7 @@ FactoryGirl.define do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
factory(:admin, :parent => :"to_factory/user") do
|
11
|
-
birthday "2014-07-08T15:
|
11
|
+
birthday "2014-07-08T15:30 UTC"
|
12
12
|
email "admin@example.com"
|
13
13
|
name "Admin"
|
14
14
|
some_attributes({:a => 1})
|
@@ -2,12 +2,12 @@ describe "FileSync" do
|
|
2
2
|
let(:user) { create_user! }
|
3
3
|
let(:admin) { create_admin! }
|
4
4
|
let(:project) { create_project! }
|
5
|
-
let(:version) {
|
6
|
-
let(:expected_user_file) { File.read("./spec/example_factories
|
7
|
-
let(:expected_user_with_header_file) { File.read("./spec/example_factories
|
8
|
-
let(:expected_admin_file) { File.read("./spec/example_factories
|
9
|
-
let(:user_with_header) { File.read("./spec/example_factories
|
10
|
-
let(:user_admin_with_header) { File.read("./spec/example_factories
|
5
|
+
let(:version) { "new" }
|
6
|
+
let(:expected_user_file) { File.read("./spec/example_factories/user.rb") }
|
7
|
+
let(:expected_user_with_header_file) { File.read("./spec/example_factories/user_with_header.rb") }
|
8
|
+
let(:expected_admin_file) { File.read("./spec/example_factories/admin.rb") }
|
9
|
+
let(:user_with_header) { File.read("./spec/example_factories/user_with_header.rb") }
|
10
|
+
let(:user_admin_with_header) { File.read("./spec/example_factories/user_admin_with_header.rb") }
|
11
11
|
|
12
12
|
|
13
13
|
before do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe ToFactory::FileWriter do
|
2
2
|
let(:fw) { ToFactory::FileWriter.new }
|
3
|
-
let(:expected) { File.read "./spec/example_factories
|
3
|
+
let(:expected) { File.read "./spec/example_factories/user_with_header.rb"}
|
4
4
|
let(:user_file_contents) { File.read "./tmp/factories/to_factory/user.rb"}
|
5
5
|
let!(:user) { create_user! }
|
6
6
|
let!(:admin) { create_admin! }
|
@@ -4,13 +4,9 @@ context "full integration" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "#to_factory linting the output" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
load "./tmp/factories/to_factory/user.rb"
|
11
|
-
|
12
|
-
FactoryGirl.lint
|
13
|
-
end
|
7
|
+
ToFactory(user)
|
8
|
+
load "./tmp/factories/to_factory/user.rb"
|
9
|
+
FactoryGirl.lint
|
14
10
|
end
|
15
11
|
end
|
16
12
|
|
@@ -12,8 +12,8 @@ describe ToFactory do
|
|
12
12
|
File.read("./tmp/factories/to_factory/project.rb") rescue nil
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:expected_user_file) { File.read "./spec/example_factories
|
16
|
-
let(:expected_project_file) { File.read "./spec/example_factories
|
15
|
+
let(:expected_user_file) { File.read "./spec/example_factories/user_with_header.rb"}
|
16
|
+
let(:expected_project_file) { File.read "./spec/example_factories/project_with_header.rb"}
|
17
17
|
|
18
18
|
describe "ToFactory.definitions" do
|
19
19
|
it do
|
@@ -24,7 +24,7 @@ describe ToFactory do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "ToFactory.definition_for" do
|
27
|
-
let(:expected_user_file) { File.read "./spec/example_factories
|
27
|
+
let(:expected_user_file) { File.read "./spec/example_factories/user.rb"}
|
28
28
|
it do
|
29
29
|
expect(ToFactory.definition_for user).to match_sexp expected_user_file
|
30
30
|
end
|
@@ -41,7 +41,7 @@ describe ToFactory do
|
|
41
41
|
|
42
42
|
describe "Object#ToFactory" do
|
43
43
|
context "with multiple levels of parent classes" do
|
44
|
-
let(:filename) { "spec/example_factories/#{
|
44
|
+
let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb"}
|
45
45
|
|
46
46
|
it "gets the output order correct" do
|
47
47
|
output = "./tmp/factories/to_factory/user.rb"
|
@@ -50,7 +50,7 @@ describe ToFactory do
|
|
50
50
|
|
51
51
|
ToFactory(:root => user)
|
52
52
|
|
53
|
-
expected = File.read "spec/example_factories/#{
|
53
|
+
expected = File.read "spec/example_factories/#{'user_admin_root'}.rb"
|
54
54
|
|
55
55
|
#user, admin, super_admin, root
|
56
56
|
expect(File.read(output)).to match_sexp expected
|
@@ -116,20 +116,9 @@ describe ToFactory do
|
|
116
116
|
|
117
117
|
context "with a name for the factory" do
|
118
118
|
it "appends to the file" do
|
119
|
-
|
120
|
-
user_file_includes('factory(:"to_factory/user"')
|
121
|
-
else
|
122
|
-
user_file_includes('Factory.define(:"to_factory/user"')
|
123
|
-
end
|
124
|
-
|
119
|
+
user_file_includes('factory(:"to_factory/user"')
|
125
120
|
ToFactory(:specific_user => user)
|
126
|
-
|
127
|
-
user_file_includes('factory(:specific_user, :parent => :"to_factory/user"')
|
128
|
-
else
|
129
|
-
user_file_includes('Factory.define(:specific_user, :parent => :"to_factory/user"')
|
130
|
-
end
|
131
|
-
|
132
|
-
|
121
|
+
user_file_includes('factory(:specific_user, :parent => :"to_factory/user"')
|
133
122
|
end
|
134
123
|
end
|
135
124
|
|
data/spec/spec_helper.rb
CHANGED
@@ -28,15 +28,8 @@ require "./spec/support/models/project"
|
|
28
28
|
require "./spec/support/match_sexp"
|
29
29
|
require "./spec/support/data_creation"
|
30
30
|
|
31
|
-
module ToFactory::SpecSyntaxHelpers
|
32
|
-
def version
|
33
|
-
ToFactory.new_syntax? ? "new" : "old"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
31
|
RSpec.configure do |config|
|
38
32
|
config.include ToFactory::DataCreation
|
39
|
-
config.include ToFactory::SpecSyntaxHelpers
|
40
33
|
|
41
34
|
config.before :suite do
|
42
35
|
ActiveRecord::Base.tap do |base|
|
@@ -17,9 +17,7 @@ describe ToFactory::FileWriter do
|
|
17
17
|
"to_factory/project" => [project_representation]
|
18
18
|
})
|
19
19
|
|
20
|
-
|
21
|
-
expect(user_file).to match /FactoryGirl.define do/
|
22
|
-
end
|
20
|
+
expect(user_file).to match /FactoryGirl.define do/
|
23
21
|
expect(user_file).to include "factory a"
|
24
22
|
expect(project_file).to include "factory b"
|
25
23
|
end
|
@@ -2,12 +2,12 @@ describe ToFactory::Finders::Factory do
|
|
2
2
|
describe "#call" do
|
3
3
|
before do
|
4
4
|
FileUtils.mkdir_p "./tmp/factories/to_factory"
|
5
|
-
FileUtils.cp "./spec/example_factories
|
5
|
+
FileUtils.cp "./spec/example_factories/user_admin_with_header.rb",
|
6
6
|
"./tmp/factories/to_factory/user.rb"
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:user_file_contents) { File.read "./spec/example_factories
|
10
|
-
let(:admin_file_contents){ File.read "./spec/example_factories
|
9
|
+
let(:user_file_contents) { File.read "./spec/example_factories/user.rb"}
|
10
|
+
let(:admin_file_contents){ File.read "./spec/example_factories/admin.rb" }
|
11
11
|
|
12
12
|
it "reads all the factories" do
|
13
13
|
finder = ToFactory::Finders::Factory.new
|
@@ -7,12 +7,28 @@ describe ToFactory::Generation::Attribute do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
describe "#format" do
|
11
|
+
it "formats Date, Time, DateTime" do
|
12
|
+
Time.zone= "UTC"
|
13
|
+
time_string ="2011-12-13T14:15 UTC"
|
14
|
+
|
15
|
+
expect(attribute.format(Time .parse(time_string))).to eq "2011-12-13T14:15 UTC".inspect
|
16
|
+
expect(attribute.format(Date .parse(time_string))).to eq "2011-12-13".inspect
|
17
|
+
expect(attribute.format(DateTime.parse(time_string))).to eq "2011-12-13T14:15 +00:00".inspect
|
18
|
+
end
|
19
|
+
|
20
|
+
it "formats Integer, Float"do
|
21
|
+
expect(attribute.format(123)) .to eq "123"
|
22
|
+
expect(attribute.format(123.0)).to eq "123.0"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
10
27
|
describe "#inspect_value" do
|
11
28
|
it do
|
12
29
|
expect(attribute.inspect_value({:a => 1})).to eq "({:a => 1})"
|
13
30
|
end
|
14
|
-
|
15
|
-
it do
|
31
|
+
it "formats hashes correctly" do
|
16
32
|
hash = ActiveSupport::OrderedHash.new
|
17
33
|
hash[{"with" => :hash}] = "keys"
|
18
34
|
hash[2] = "integers"
|
@@ -0,0 +1,64 @@
|
|
1
|
+
describe ToFactory::Generation::Factory do
|
2
|
+
before(:each) do
|
3
|
+
ToFactory::User.destroy_all
|
4
|
+
ActiveRecord::Base.connection.execute "delete from sqlite_sequence where name = 'users'"
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:birthday) do
|
8
|
+
Time.find_zone("UTC").parse("2014-07-08T15:30 UTC")
|
9
|
+
end
|
10
|
+
|
11
|
+
let!(:user) { create_user! }
|
12
|
+
|
13
|
+
let(:representation) { ToFactory::Representation.from(user) }
|
14
|
+
let(:generator) { ToFactory::Generation::Factory.new representation }
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
describe "#header" do
|
19
|
+
it do
|
20
|
+
expect(generator.header{}).to match_sexp <<-eof.strip_heredoc
|
21
|
+
factory(:"to_factory/user") do
|
22
|
+
end
|
23
|
+
eof
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#attributes" do
|
28
|
+
let(:representation) do
|
29
|
+
double(:attributes => {"something" => "something",
|
30
|
+
:id => 123,
|
31
|
+
:created_at => anything,
|
32
|
+
:created_on => anything,
|
33
|
+
:updated_at => anything,
|
34
|
+
:updated_on => anything,
|
35
|
+
nil => nil})
|
36
|
+
end
|
37
|
+
it "ignores blank keys, :id, :created_at, :updated_at, :created_on, :updated_on" do
|
38
|
+
expect(generator.attributes).to eq({"something" => "something"})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe "#factory_attribute" do
|
42
|
+
it do
|
43
|
+
expect(generator.factory_attribute(:name, nil)) .to eq ' name nil'
|
44
|
+
expect(generator.factory_attribute(:name, "Jeff")).to eq ' name "Jeff"'
|
45
|
+
expect(generator.factory_attribute(:id, 8)) .to eq ' id 8'
|
46
|
+
end
|
47
|
+
it "generates usable datetime strings" do
|
48
|
+
output = generator.factory_attribute(:birthday, birthday)
|
49
|
+
expect(output).to eq ' birthday "2014-07-08T15:30 UTC"'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#ToFactory" do
|
54
|
+
let(:expected) do
|
55
|
+
File.read "./spec/example_factories/user.rb"
|
56
|
+
end
|
57
|
+
|
58
|
+
it do
|
59
|
+
expect(generator.to_factory).to match_sexp expected
|
60
|
+
result = ToFactory(user).values.first.first
|
61
|
+
expect(result.definition).to match_sexp expected
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,31 +1,45 @@
|
|
1
1
|
describe ToFactory::Parsing::File do
|
2
|
-
let(:user_contents) { File.read "spec/example_factories
|
3
|
-
let(:admin_contents) { File.read "spec/example_factories
|
2
|
+
let(:user_contents) { File.read "spec/example_factories/user.rb" }
|
3
|
+
let(:admin_contents) { File.read "spec/example_factories/admin.rb"}
|
4
4
|
|
5
5
|
let(:parser) { ToFactory::Parsing::File.from_file(filename) }
|
6
6
|
|
7
|
+
context "with non-parseable factories" do
|
8
|
+
let(:dynamic_content) do
|
9
|
+
<<-RUBY
|
10
|
+
[ 0, 1, 2, 3, 4].each do |i|
|
11
|
+
Factory.define(:"user_\#{i}", :parent => :"to_factory/user") do |o|
|
12
|
+
p.project_statuses = statuses
|
13
|
+
end
|
14
|
+
end
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
let(:instance) { ToFactory::Parsing::File.new(dynamic_content) }
|
18
|
+
|
19
|
+
it do
|
20
|
+
expect(Kernel).to receive(:warn).with(/#{dynamic_content}/).at_least :once
|
21
|
+
expect(lambda{instance.parse}).not_to raise_error
|
22
|
+
result = instance.parse
|
23
|
+
expect(result).to be_a Array
|
24
|
+
expect(result[0]).to be_a ToFactory::NullRepresentation
|
25
|
+
expect(result[0].definition).to match_sexp dynamic_content
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
7
29
|
describe "#multiple_factories? and #header?" do
|
8
30
|
context "new syntax" do
|
9
|
-
tests =
|
10
|
-
|
11
|
-
#file, multiple, header
|
31
|
+
tests = #file, multiple, header
|
12
32
|
[
|
13
33
|
["user", false, false],
|
14
34
|
["user_with_header", false, true],
|
15
35
|
["user_admin", true, false],
|
16
36
|
["user_admin_with_header", true, true]
|
17
37
|
]
|
18
|
-
else
|
19
|
-
[
|
20
|
-
["user", false, false],
|
21
|
-
["user_admin", true, false],
|
22
|
-
]
|
23
|
-
end
|
24
38
|
|
25
39
|
tests.each do |file, multiple, header|
|
26
40
|
context "with #{header ? 'header' : 'no header'} and #{multiple ? 'multiple factories' : 'one factory'}" do
|
27
41
|
context "file: #{file}" do
|
28
|
-
let(:filename) { "spec/example_factories/#{
|
42
|
+
let(:filename) { "spec/example_factories/#{file}.rb"}
|
29
43
|
|
30
44
|
it { expect(parser.multiple_factories?).to eq multiple }
|
31
45
|
it { expect(parser.header?).to eq header }
|
@@ -37,7 +51,7 @@ describe ToFactory::Parsing::File do
|
|
37
51
|
|
38
52
|
describe "#parse" do
|
39
53
|
context "with multiple levels of parent classes" do
|
40
|
-
let(:filename) { "spec/example_factories/#{
|
54
|
+
let(:filename) { "spec/example_factories/#{'user_admin_super_admin'}.rb"}
|
41
55
|
|
42
56
|
it do
|
43
57
|
result = parser.parse
|
@@ -47,7 +61,7 @@ describe ToFactory::Parsing::File do
|
|
47
61
|
end
|
48
62
|
|
49
63
|
context "file: user" do
|
50
|
-
let(:filename) { "spec/example_factories/#{
|
64
|
+
let(:filename) { "spec/example_factories/#{'user'}.rb"}
|
51
65
|
|
52
66
|
it do
|
53
67
|
result = parser.parse
|
@@ -57,7 +71,7 @@ describe ToFactory::Parsing::File do
|
|
57
71
|
end
|
58
72
|
|
59
73
|
context "file: user_with_header" do
|
60
|
-
let(:filename) { "spec/example_factories/#{
|
74
|
+
let(:filename) { "spec/example_factories/#{'user_with_header'}.rb"}
|
61
75
|
|
62
76
|
it do
|
63
77
|
result = parser.parse
|
@@ -67,7 +81,7 @@ describe ToFactory::Parsing::File do
|
|
67
81
|
end
|
68
82
|
|
69
83
|
context "file: user_admin" do
|
70
|
-
let(:filename) { "spec/example_factories/#{
|
84
|
+
let(:filename) { "spec/example_factories/#{'user_admin'}.rb"}
|
71
85
|
|
72
86
|
it do
|
73
87
|
result = parser.parse
|
@@ -80,7 +94,7 @@ describe ToFactory::Parsing::File do
|
|
80
94
|
end
|
81
95
|
|
82
96
|
context "file: user_admin_with_header" do
|
83
|
-
let(:filename) { "spec/example_factories/#{
|
97
|
+
let(:filename) { "spec/example_factories/#{'user_admin_with_header'}.rb"}
|
84
98
|
|
85
99
|
it do
|
86
100
|
result = parser.parse
|
data/to_factory.gemspec
CHANGED
@@ -19,31 +19,16 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "sqlite3" , "~> 1.3.6"
|
22
|
-
|
23
|
-
if RUBY_VERSION =~ /^1\.8/
|
24
|
-
spec.add_development_dependency "ruby-debug"
|
25
|
-
spec.add_development_dependency "database_cleaner", "~> 0.3"
|
26
|
-
else
|
27
|
-
spec.add_development_dependency "database_cleaner", "~> 1.4.0"
|
28
|
-
end
|
22
|
+
spec.add_development_dependency "database_cleaner", "~> 1.4.0"
|
29
23
|
|
30
24
|
if RUBY_VERSION =~ /^2\.\d/
|
31
25
|
spec.add_development_dependency "pry-byebug"
|
32
26
|
end
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
spec.add_dependency "ruby2ruby"
|
37
|
-
|
38
|
-
if old_active_record
|
39
|
-
spec.add_dependency 'activerecord', ">2.0", "< 4.0"
|
40
|
-
spec.add_dependency 'i18n', "< 0.7"
|
41
|
-
spec.add_development_dependency "factory_girl", "< 2.0"
|
42
|
-
else
|
43
|
-
spec.add_dependency 'activerecord', ">3.0"
|
44
|
-
spec.add_development_dependency "factory_girl", "~> 4.5"
|
45
|
-
end
|
46
|
-
|
28
|
+
spec.add_development_dependency "factory_girl", "~> 4.5"
|
47
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
48
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
|
32
|
+
spec.add_dependency "ruby2ruby"
|
33
|
+
spec.add_dependency "activerecord", "> 4.0"
|
49
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Burns
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -53,75 +53,75 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: factory_girl
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '4.5'
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '3.0'
|
76
|
-
type: :
|
76
|
+
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '10.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '10.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: ruby2ruby
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
104
|
-
type: :
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: activerecord
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
118
|
-
type: :
|
117
|
+
version: '4.0'
|
118
|
+
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '4.0'
|
125
125
|
description: Autogenerate and append/create factory_girl definitions from the console
|
126
126
|
email:
|
127
127
|
- markthedeveloper@gmail.com
|
@@ -149,8 +149,7 @@ files:
|
|
149
149
|
- lib/to_factory/klass_inference.rb
|
150
150
|
- lib/to_factory/options_parser.rb
|
151
151
|
- lib/to_factory/parsing/file.rb
|
152
|
-
- lib/to_factory/parsing/
|
153
|
-
- lib/to_factory/parsing/old_syntax.rb
|
152
|
+
- lib/to_factory/parsing/ruby_parsing_helpers.rb
|
154
153
|
- lib/to_factory/parsing/syntax.rb
|
155
154
|
- lib/to_factory/representation.rb
|
156
155
|
- lib/to_factory/version.rb
|
@@ -159,23 +158,15 @@ files:
|
|
159
158
|
- spec/db/migrate/3_create_not_namespaced.rb
|
160
159
|
- spec/db/migrate/4_add_birthday_to_users.rb
|
161
160
|
- spec/db/migrate/5_add_serialized_attributes_to_users.rb
|
162
|
-
- spec/example_factories/
|
163
|
-
- spec/example_factories/
|
164
|
-
- spec/example_factories/
|
165
|
-
- spec/example_factories/
|
166
|
-
- spec/example_factories/
|
167
|
-
- spec/example_factories/
|
168
|
-
- spec/example_factories/
|
169
|
-
- spec/example_factories/
|
170
|
-
- spec/example_factories/
|
171
|
-
- spec/example_factories/old_syntax/admin.rb
|
172
|
-
- spec/example_factories/old_syntax/project_with_header.rb
|
173
|
-
- spec/example_factories/old_syntax/user.rb
|
174
|
-
- spec/example_factories/old_syntax/user_admin.rb
|
175
|
-
- spec/example_factories/old_syntax/user_admin_root.rb
|
176
|
-
- spec/example_factories/old_syntax/user_admin_super_admin.rb
|
177
|
-
- spec/example_factories/old_syntax/user_admin_with_header.rb
|
178
|
-
- spec/example_factories/old_syntax/user_with_header.rb
|
161
|
+
- spec/example_factories/admin.rb
|
162
|
+
- spec/example_factories/admin_with_header.rb
|
163
|
+
- spec/example_factories/project_with_header.rb
|
164
|
+
- spec/example_factories/user.rb
|
165
|
+
- spec/example_factories/user_admin.rb
|
166
|
+
- spec/example_factories/user_admin_root.rb
|
167
|
+
- spec/example_factories/user_admin_super_admin.rb
|
168
|
+
- spec/example_factories/user_admin_with_header.rb
|
169
|
+
- spec/example_factories/user_with_header.rb
|
179
170
|
- spec/integration/config_spec.rb
|
180
171
|
- spec/integration/file_sync_spec.rb
|
181
172
|
- spec/integration/file_writer_spec.rb
|
@@ -193,7 +184,7 @@ files:
|
|
193
184
|
- spec/unit/finders/factory_spec.rb
|
194
185
|
- spec/unit/finders/model_spec.rb
|
195
186
|
- spec/unit/generation/attribute_spec.rb
|
196
|
-
- spec/unit/
|
187
|
+
- spec/unit/generation/factory_spec.rb
|
197
188
|
- spec/unit/parsing/file_spec.rb
|
198
189
|
- spec/unit/parsing/klass_inference_spec.rb
|
199
190
|
- tmp/.keep
|
@@ -228,23 +219,15 @@ test_files:
|
|
228
219
|
- spec/db/migrate/3_create_not_namespaced.rb
|
229
220
|
- spec/db/migrate/4_add_birthday_to_users.rb
|
230
221
|
- spec/db/migrate/5_add_serialized_attributes_to_users.rb
|
231
|
-
- spec/example_factories/
|
232
|
-
- spec/example_factories/
|
233
|
-
- spec/example_factories/
|
234
|
-
- spec/example_factories/
|
235
|
-
- spec/example_factories/
|
236
|
-
- spec/example_factories/
|
237
|
-
- spec/example_factories/
|
238
|
-
- spec/example_factories/
|
239
|
-
- spec/example_factories/
|
240
|
-
- spec/example_factories/old_syntax/admin.rb
|
241
|
-
- spec/example_factories/old_syntax/project_with_header.rb
|
242
|
-
- spec/example_factories/old_syntax/user.rb
|
243
|
-
- spec/example_factories/old_syntax/user_admin.rb
|
244
|
-
- spec/example_factories/old_syntax/user_admin_root.rb
|
245
|
-
- spec/example_factories/old_syntax/user_admin_super_admin.rb
|
246
|
-
- spec/example_factories/old_syntax/user_admin_with_header.rb
|
247
|
-
- spec/example_factories/old_syntax/user_with_header.rb
|
222
|
+
- spec/example_factories/admin.rb
|
223
|
+
- spec/example_factories/admin_with_header.rb
|
224
|
+
- spec/example_factories/project_with_header.rb
|
225
|
+
- spec/example_factories/user.rb
|
226
|
+
- spec/example_factories/user_admin.rb
|
227
|
+
- spec/example_factories/user_admin_root.rb
|
228
|
+
- spec/example_factories/user_admin_super_admin.rb
|
229
|
+
- spec/example_factories/user_admin_with_header.rb
|
230
|
+
- spec/example_factories/user_with_header.rb
|
248
231
|
- spec/integration/config_spec.rb
|
249
232
|
- spec/integration/file_sync_spec.rb
|
250
233
|
- spec/integration/file_writer_spec.rb
|
@@ -262,6 +245,7 @@ test_files:
|
|
262
245
|
- spec/unit/finders/factory_spec.rb
|
263
246
|
- spec/unit/finders/model_spec.rb
|
264
247
|
- spec/unit/generation/attribute_spec.rb
|
265
|
-
- spec/unit/
|
248
|
+
- spec/unit/generation/factory_spec.rb
|
266
249
|
- spec/unit/parsing/file_spec.rb
|
267
250
|
- spec/unit/parsing/klass_inference_spec.rb
|
251
|
+
has_rdoc:
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ToFactory
|
2
|
-
module Parsing
|
3
|
-
class NewSyntax < Syntax
|
4
|
-
def header?
|
5
|
-
sexp[1][1][1] == :FactoryGirl rescue false
|
6
|
-
end
|
7
|
-
|
8
|
-
def parent_from(x)
|
9
|
-
# e.g.
|
10
|
-
#s(:call, nil, :factory, s(:lit, :admin), s(:hash, s(:lit, :parent), s(:lit, :"to_factory/user")))
|
11
|
-
x[1][4][2][1]
|
12
|
-
rescue NoMethodError
|
13
|
-
# e.g.
|
14
|
-
#s(:call, nil, :factory, s(:lit, :"to_factory/user"))
|
15
|
-
x[1][3][1]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Factory.define(:"to_factory/user") do |o|
|
2
|
-
o.birthday "2014-07-08T15:30Z"
|
3
|
-
o.email "test@example.com"
|
4
|
-
o.name "Jeff"
|
5
|
-
o.some_attributes({:a => 1})
|
6
|
-
o.some_id 8
|
7
|
-
end
|
8
|
-
|
9
|
-
Factory.define(:admin, :parent => :"to_factory/user") do |o|
|
10
|
-
o.birthday "2014-07-08T15:30Z"
|
11
|
-
o.email "admin@example.com"
|
12
|
-
o.name "Admin"
|
13
|
-
o.some_attributes({:a => 1})
|
14
|
-
o.some_id 9
|
15
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
Factory.define(:"to_factory/user") do |o|
|
2
|
-
o.name("User")
|
3
|
-
end
|
4
|
-
|
5
|
-
Factory.define(:root, :parent => :"to_factory/user") do |o|
|
6
|
-
o.birthday "2014-07-08T15:30Z"
|
7
|
-
o.email "test@example.com"
|
8
|
-
o.name "Jeff"
|
9
|
-
o.some_attributes({:a => 1})
|
10
|
-
o.some_id 8
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
Factory.define(:admin, :parent => :"to_factory/user") do |o|
|
15
|
-
o.name("Admin")
|
16
|
-
end
|
17
|
-
|
18
|
-
Factory.define(:super_admin, :parent => :admin) do |o|
|
19
|
-
o.name("Super Admin")
|
20
|
-
end
|
21
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Factory.define(:"to_factory/user") do |o|
|
2
|
-
o.birthday "2014-07-08T15:30Z"
|
3
|
-
o.email "test@example.com"
|
4
|
-
o.name "Jeff"
|
5
|
-
o.some_attributes({:a => 1})
|
6
|
-
o.some_id 8
|
7
|
-
end
|
8
|
-
|
9
|
-
Factory.define(:admin, :parent => :"to_factory/user") do |o|
|
10
|
-
o.birthday "2014-07-08T15:30Z"
|
11
|
-
o.email "admin@example.com"
|
12
|
-
o.name "Admin"
|
13
|
-
o.some_attributes({:a => 1})
|
14
|
-
o.some_id 9
|
15
|
-
end
|
data/spec/unit/generator_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
describe ToFactory::Generation::Factory do
|
2
|
-
before(:each) do
|
3
|
-
ToFactory::User.destroy_all
|
4
|
-
ActiveRecord::Base.connection.execute "delete from sqlite_sequence where name = 'users'"
|
5
|
-
end
|
6
|
-
|
7
|
-
let(:birthday) do
|
8
|
-
Time.find_zone("UTC").parse("2014-07-08T15:30Z")
|
9
|
-
end
|
10
|
-
|
11
|
-
let!(:user) { create_user! }
|
12
|
-
|
13
|
-
let(:representation) { ToFactory::Representation.from(user) }
|
14
|
-
let(:generator) { ToFactory::Generation::Factory.new representation }
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
describe "#header" do
|
19
|
-
it do
|
20
|
-
if ToFactory.new_syntax?
|
21
|
-
expect(generator.header{}).to match_sexp <<-eof.strip_heredoc
|
22
|
-
factory(:"to_factory/user") do
|
23
|
-
end
|
24
|
-
eof
|
25
|
-
else
|
26
|
-
expect(generator.header{}).to match_sexp <<-eof.strip_heredoc
|
27
|
-
Factory.define(:"to_factory/user") do |o|
|
28
|
-
end
|
29
|
-
eof
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#factory_attribute" do
|
35
|
-
it do
|
36
|
-
if ToFactory.new_syntax?
|
37
|
-
expect(generator.factory_attribute(:name, nil)) .to eq ' name nil'
|
38
|
-
expect(generator.factory_attribute(:name, "Jeff")).to eq ' name "Jeff"'
|
39
|
-
expect(generator.factory_attribute(:id, 8)) .to eq ' id 8'
|
40
|
-
|
41
|
-
else
|
42
|
-
expect(generator.factory_attribute(:name, nil)) .to eq ' o.name nil'
|
43
|
-
expect(generator.factory_attribute(:name, "Jeff")).to eq ' o.name "Jeff"'
|
44
|
-
expect(generator.factory_attribute(:id, 8)) .to eq ' o.id 8'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
it "generates usable datetime strings" do
|
48
|
-
output = generator.factory_attribute(:birthday, birthday)
|
49
|
-
if ToFactory.new_syntax?
|
50
|
-
expect(output).to eq ' birthday "2014-07-08T15:30Z"'
|
51
|
-
else
|
52
|
-
expect(output).to eq ' o.birthday "2014-07-08T15:30Z"'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#ToFactory" do
|
58
|
-
let(:expected) do
|
59
|
-
File.read "./spec/example_factories/#{version}_syntax/user.rb"
|
60
|
-
end
|
61
|
-
|
62
|
-
it do
|
63
|
-
expect(generator.to_factory).to match_sexp expected
|
64
|
-
result = ToFactory(user).values.first.first
|
65
|
-
expect(result.definition).to match_sexp expected
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|