vitalish-factory_girl 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.rdoc +67 -121
  2. data/Rakefile +103 -29
  3. data/VERSION +1 -0
  4. data/lib/factory_girl/aliases.rb +32 -3
  5. data/lib/factory_girl/attribute/association.rb +1 -1
  6. data/lib/factory_girl/attribute/callback.rb +1 -1
  7. data/lib/factory_girl/attribute/dynamic.rb +3 -3
  8. data/lib/factory_girl/attribute/static.rb +1 -1
  9. data/lib/factory_girl/attribute.rb +3 -3
  10. data/lib/factory_girl/factory.rb +354 -164
  11. data/lib/factory_girl/proxy/attributes_for.rb +1 -1
  12. data/lib/factory_girl/proxy/build.rb +5 -7
  13. data/lib/factory_girl/proxy/create.rb +3 -2
  14. data/lib/factory_girl/proxy/stub.rb +5 -19
  15. data/lib/factory_girl/proxy.rb +23 -7
  16. data/lib/factory_girl/sequence.rb +40 -5
  17. data/lib/factory_girl/step_definitions.rb +13 -19
  18. data/lib/factory_girl/syntax/blueprint.rb +5 -5
  19. data/lib/factory_girl/syntax/generate.rb +8 -13
  20. data/lib/factory_girl/syntax/make.rb +7 -9
  21. data/lib/factory_girl/syntax/sham.rb +8 -11
  22. data/lib/factory_girl/syntax.rb +7 -7
  23. data/lib/factory_girl.rb +19 -8
  24. data/spec/factory_girl/aliases_spec.rb +5 -9
  25. data/spec/factory_girl/attribute/association_spec.rb +4 -4
  26. data/spec/factory_girl/attribute/callback_spec.rb +4 -4
  27. data/spec/factory_girl/attribute/dynamic_spec.rb +10 -21
  28. data/spec/factory_girl/attribute/static_spec.rb +6 -6
  29. data/spec/factory_girl/attribute_spec.rb +6 -6
  30. data/spec/factory_girl/factory_spec.rb +465 -305
  31. data/spec/factory_girl/proxy/attributes_for_spec.rb +3 -3
  32. data/spec/factory_girl/proxy/build_spec.rb +13 -18
  33. data/spec/factory_girl/proxy/create_spec.rb +13 -18
  34. data/spec/factory_girl/proxy/stub_spec.rb +6 -7
  35. data/spec/factory_girl/proxy_spec.rb +3 -3
  36. data/spec/factory_girl/sequence_spec.rb +39 -16
  37. data/spec/factory_girl/syntax/blueprint_spec.rb +34 -0
  38. data/spec/factory_girl/syntax/generate_spec.rb +57 -0
  39. data/spec/factory_girl/syntax/make_spec.rb +35 -0
  40. data/spec/factory_girl/syntax/sham_spec.rb +35 -0
  41. data/spec/integration_spec.rb +304 -0
  42. data/spec/models.rb +43 -0
  43. data/spec/spec_helper.rb +10 -85
  44. metadata +15 -3
data/spec/models.rb ADDED
@@ -0,0 +1,43 @@
1
+ ActiveRecord::Base.establish_connection(
2
+ :adapter => 'sqlite3',
3
+ :database => File.join(File.dirname(__FILE__), 'test.db')
4
+ )
5
+
6
+ class CreateSchema < ActiveRecord::Migration
7
+ def self.up
8
+ create_table :users, :force => true do |t|
9
+ t.string :first_name
10
+ t.string :last_name
11
+ t.string :email
12
+ t.string :username
13
+ t.boolean :admin, :default => false
14
+ end
15
+
16
+ create_table :posts, :force => true do |t|
17
+ t.string :name
18
+ t.integer :author_id
19
+ end
20
+
21
+ create_table :business, :force => true do |t|
22
+ t.string :name
23
+ t.integer :owner_id
24
+ end
25
+ end
26
+ end
27
+
28
+ CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
29
+
30
+ class User < ActiveRecord::Base
31
+ validates_presence_of :first_name, :last_name, :email
32
+ has_many :posts, :foreign_key => 'author_id'
33
+ end
34
+
35
+ class Business < ActiveRecord::Base
36
+ validates_presence_of :name, :owner_id
37
+ belongs_to :owner, :class_name => 'User'
38
+ end
39
+
40
+ class Post < ActiveRecord::Base
41
+ validates_presence_of :name, :author_id
42
+ belongs_to :author, :class_name => 'User'
43
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,93 +1,18 @@
1
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
- $LOAD_PATH << File.join(File.dirname(__FILE__))
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $: << File.join(File.dirname(__FILE__))
3
3
 
4
4
  require 'rubygems'
5
- require 'rspec'
6
- require 'rspec/autorun'
7
- require 'rr'
8
-
9
- require 'factory_girl'
10
-
11
- module RR
12
- module Adapters
13
- module Rspec
14
- def self.included(mod)
15
- RSpec.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
16
- end
17
- end
18
- end
19
- end
20
-
21
- RSpec.configure do |config|
22
- config.mock_framework = :rr
23
- RSpec::Core::ExampleGroup.send(:include, RR::Adapters::Rspec)
24
- config.after do
25
- FactoryGirl.factories.clear
26
- FactoryGirl.sequences.clear
27
- end
28
- end
29
5
 
30
- module DefinesConstants
31
- def self.included(example_group)
32
- example_group.class_eval do
33
- before do
34
- @defined_constants = []
35
- @created_tables = []
36
- end
6
+ require 'activerecord'
37
7
 
38
- after do
39
- @defined_constants.reverse.each do |path|
40
- namespace, class_name = *constant_path(path)
41
- namespace.send(:remove_const, class_name)
42
- end
43
-
44
- @created_tables.each do |table_name|
45
- ActiveRecord::Base.
46
- connection.
47
- execute("DROP TABLE IF EXISTS #{table_name}")
48
- end
49
- end
50
-
51
- def define_class(path, base = Object, &block)
52
- namespace, class_name = *constant_path(path)
53
- klass = Class.new(base)
54
- namespace.const_set(class_name, klass)
55
- klass.class_eval(&block) if block_given?
56
- @defined_constants << path
57
- klass
58
- end
59
-
60
- def define_model(name, columns = {}, &block)
61
- model = define_class(name, ActiveRecord::Base, &block)
62
- create_table(model.table_name) do |table|
63
- columns.each do |name, type|
64
- table.column name, type
65
- end
66
- end
67
- model
68
- end
8
+ require 'spec'
9
+ require 'spec/autorun'
10
+ require 'rr'
69
11
 
70
- def create_table(table_name, &block)
71
- connection = ActiveRecord::Base.connection
12
+ require 'models'
72
13
 
73
- begin
74
- connection.execute("DROP TABLE IF EXISTS #{table_name}")
75
- connection.create_table(table_name, &block)
76
- @created_tables << table_name
77
- connection
78
- rescue Exception => exception
79
- connection.execute("DROP TABLE IF EXISTS #{table_name}")
80
- raise exception
81
- end
82
- end
14
+ require 'factory_girl'
83
15
 
84
- def constant_path(constant_name)
85
- names = constant_name.split('::')
86
- class_name = names.pop
87
- namespace = names.inject(Object) { |result, name| result.const_get(name) }
88
- [namespace, class_name]
89
- end
90
- end
91
- end
16
+ Spec::Runner.configure do |config|
17
+ config.mock_with RR::Adapters::Rspec
92
18
  end
93
-
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitalish-factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 5
10
- version: 1.2.5
9
+ - 6
10
+ version: 1.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Ferris
@@ -35,6 +35,7 @@ files:
35
35
  - LICENSE
36
36
  - README.rdoc
37
37
  - Rakefile
38
+ - VERSION
38
39
  - lib/factory_girl.rb
39
40
  - lib/factory_girl/aliases.rb
40
41
  - lib/factory_girl/attribute.rb
@@ -68,6 +69,12 @@ files:
68
69
  - spec/factory_girl/proxy/stub_spec.rb
69
70
  - spec/factory_girl/proxy_spec.rb
70
71
  - spec/factory_girl/sequence_spec.rb
72
+ - spec/factory_girl/syntax/blueprint_spec.rb
73
+ - spec/factory_girl/syntax/generate_spec.rb
74
+ - spec/factory_girl/syntax/make_spec.rb
75
+ - spec/factory_girl/syntax/sham_spec.rb
76
+ - spec/integration_spec.rb
77
+ - spec/models.rb
71
78
  - spec/spec_helper.rb
72
79
  has_rdoc: true
73
80
  homepage: http://thoughtbot.com/projects/factory_girl
@@ -117,3 +124,8 @@ test_files:
117
124
  - spec/factory_girl/proxy/stub_spec.rb
118
125
  - spec/factory_girl/proxy_spec.rb
119
126
  - spec/factory_girl/sequence_spec.rb
127
+ - spec/factory_girl/syntax/blueprint_spec.rb
128
+ - spec/factory_girl/syntax/generate_spec.rb
129
+ - spec/factory_girl/syntax/make_spec.rb
130
+ - spec/factory_girl/syntax/sham_spec.rb
131
+ - spec/integration_spec.rb