vitalish-factory_girl 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CONTRIBUTION_GUIDELINES.rdoc +9 -0
  2. data/Changelog +29 -0
  3. data/LICENSE +19 -0
  4. data/README.rdoc +282 -0
  5. data/Rakefile +66 -0
  6. data/lib/factory_girl.rb +24 -0
  7. data/lib/factory_girl/aliases.rb +21 -0
  8. data/lib/factory_girl/attribute.rb +29 -0
  9. data/lib/factory_girl/attribute/association.rb +20 -0
  10. data/lib/factory_girl/attribute/callback.rb +16 -0
  11. data/lib/factory_girl/attribute/dynamic.rb +20 -0
  12. data/lib/factory_girl/attribute/static.rb +17 -0
  13. data/lib/factory_girl/factory.rb +215 -0
  14. data/lib/factory_girl/proxy.rb +77 -0
  15. data/lib/factory_girl/proxy/attributes_for.rb +21 -0
  16. data/lib/factory_girl/proxy/build.rb +32 -0
  17. data/lib/factory_girl/proxy/create.rb +12 -0
  18. data/lib/factory_girl/proxy/stub.rb +64 -0
  19. data/lib/factory_girl/sequence.rb +28 -0
  20. data/lib/factory_girl/step_definitions.rb +60 -0
  21. data/lib/factory_girl/syntax.rb +12 -0
  22. data/lib/factory_girl/syntax/blueprint.rb +42 -0
  23. data/lib/factory_girl/syntax/generate.rb +73 -0
  24. data/lib/factory_girl/syntax/make.rb +41 -0
  25. data/lib/factory_girl/syntax/sham.rb +45 -0
  26. data/spec/factory_girl/aliases_spec.rb +33 -0
  27. data/spec/factory_girl/attribute/association_spec.rb +29 -0
  28. data/spec/factory_girl/attribute/callback_spec.rb +23 -0
  29. data/spec/factory_girl/attribute/dynamic_spec.rb +60 -0
  30. data/spec/factory_girl/attribute/static_spec.rb +29 -0
  31. data/spec/factory_girl/attribute_spec.rb +30 -0
  32. data/spec/factory_girl/factory_spec.rb +411 -0
  33. data/spec/factory_girl/proxy/attributes_for_spec.rb +52 -0
  34. data/spec/factory_girl/proxy/build_spec.rb +86 -0
  35. data/spec/factory_girl/proxy/create_spec.rb +99 -0
  36. data/spec/factory_girl/proxy/stub_spec.rb +80 -0
  37. data/spec/factory_girl/proxy_spec.rb +84 -0
  38. data/spec/factory_girl/sequence_spec.rb +43 -0
  39. data/spec/spec_helper.rb +93 -0
  40. metadata +119 -0
@@ -0,0 +1,93 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
3
+
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
+
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
37
+
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
69
+
70
+ def create_table(table_name, &block)
71
+ connection = ActiveRecord::Base.connection
72
+
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
83
+
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
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vitalish-factory_girl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 4
10
+ version: 1.2.4
11
+ platform: ruby
12
+ authors:
13
+ - Joe Ferris
14
+ - Vitalish
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-12-01 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.
24
+ email: jferris@thoughtbot.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - LICENSE
31
+ - README.rdoc
32
+ files:
33
+ - CONTRIBUTION_GUIDELINES.rdoc
34
+ - Changelog
35
+ - LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/factory_girl.rb
39
+ - lib/factory_girl/aliases.rb
40
+ - lib/factory_girl/attribute.rb
41
+ - lib/factory_girl/attribute/association.rb
42
+ - lib/factory_girl/attribute/callback.rb
43
+ - lib/factory_girl/attribute/dynamic.rb
44
+ - lib/factory_girl/attribute/static.rb
45
+ - lib/factory_girl/factory.rb
46
+ - lib/factory_girl/proxy.rb
47
+ - lib/factory_girl/proxy/attributes_for.rb
48
+ - lib/factory_girl/proxy/build.rb
49
+ - lib/factory_girl/proxy/create.rb
50
+ - lib/factory_girl/proxy/stub.rb
51
+ - lib/factory_girl/sequence.rb
52
+ - lib/factory_girl/step_definitions.rb
53
+ - lib/factory_girl/syntax.rb
54
+ - lib/factory_girl/syntax/blueprint.rb
55
+ - lib/factory_girl/syntax/generate.rb
56
+ - lib/factory_girl/syntax/make.rb
57
+ - lib/factory_girl/syntax/sham.rb
58
+ - spec/factory_girl/aliases_spec.rb
59
+ - spec/factory_girl/attribute/association_spec.rb
60
+ - spec/factory_girl/attribute/callback_spec.rb
61
+ - spec/factory_girl/attribute/dynamic_spec.rb
62
+ - spec/factory_girl/attribute/static_spec.rb
63
+ - spec/factory_girl/attribute_spec.rb
64
+ - spec/factory_girl/factory_spec.rb
65
+ - spec/factory_girl/proxy/attributes_for_spec.rb
66
+ - spec/factory_girl/proxy/build_spec.rb
67
+ - spec/factory_girl/proxy/create_spec.rb
68
+ - spec/factory_girl/proxy/stub_spec.rb
69
+ - spec/factory_girl/proxy_spec.rb
70
+ - spec/factory_girl/sequence_spec.rb
71
+ - spec/spec_helper.rb
72
+ has_rdoc: true
73
+ homepage: http://thoughtbot.com/projects/factory_girl
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: factory_girl provides a framework and DSL for defining and using model instance factories.
106
+ test_files:
107
+ - spec/factory_girl/aliases_spec.rb
108
+ - spec/factory_girl/attribute/association_spec.rb
109
+ - spec/factory_girl/attribute/callback_spec.rb
110
+ - spec/factory_girl/attribute/dynamic_spec.rb
111
+ - spec/factory_girl/attribute/static_spec.rb
112
+ - spec/factory_girl/attribute_spec.rb
113
+ - spec/factory_girl/factory_spec.rb
114
+ - spec/factory_girl/proxy/attributes_for_spec.rb
115
+ - spec/factory_girl/proxy/build_spec.rb
116
+ - spec/factory_girl/proxy/create_spec.rb
117
+ - spec/factory_girl/proxy/stub_spec.rb
118
+ - spec/factory_girl/proxy_spec.rb
119
+ - spec/factory_girl/sequence_spec.rb