challah 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/CHANGELOG.md +9 -2
  2. data/README.md +18 -18
  3. data/lib/challah/test.rb +22 -5
  4. data/lib/challah/version.rb +1 -1
  5. data/test/audit_test.rb +32 -32
  6. data/test/controller_test.rb +9 -9
  7. data/test/cookie_store_test.rb +25 -25
  8. data/test/factories.rb +7 -7
  9. data/test/helper.rb +14 -12
  10. data/test/permission_test.rb +14 -14
  11. data/test/restrictions_controller_test.rb +29 -30
  12. data/test/role_test.rb +26 -26
  13. data/test/session_test.rb +65 -65
  14. data/test/sessions_controller_test.rb +13 -13
  15. data/test/simple_cookie_store_test.rb +25 -25
  16. data/test/user_test.rb +79 -79
  17. data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
  18. data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
  19. data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
  20. data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
  21. data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
  22. data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
  23. data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
  24. data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
  25. data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
  26. data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
  27. data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
  28. data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
  29. data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
  30. data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
  31. data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
  32. data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
  33. data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
  34. data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
  35. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
  36. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
  37. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
  38. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
  39. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
  40. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
  41. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
  42. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
  43. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
  44. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
  45. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
  46. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
  47. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
  48. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
  49. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
  50. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
  51. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
  52. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
  53. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
  54. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
  55. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
  56. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
  57. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
  58. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
  59. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
  60. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
  61. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
  62. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
  63. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
  64. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
  65. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
  66. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
  67. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
  68. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
  69. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
  70. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
  71. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
  72. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
  73. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
  74. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
  75. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
  76. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
  77. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
  78. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
  79. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
  80. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
  81. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
  82. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
  83. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
  84. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
  85. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
  86. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
  87. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
  88. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
  89. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
  90. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
  91. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
  92. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
  93. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
  94. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
  95. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
  96. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
  97. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
  98. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
  99. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
  100. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
  101. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
  102. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
  103. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
  104. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
  105. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
  106. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
  107. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
  108. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
  109. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
  110. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
  111. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
  112. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
  113. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
  114. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
  115. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
  116. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
  117. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
  118. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
  119. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
  120. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
  121. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
  122. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
  123. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
  124. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
  125. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
  126. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
  127. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
  128. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
  129. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
  130. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
  131. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
  132. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
  133. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
  134. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
  135. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
  136. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
  137. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
  138. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
  139. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
  140. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
  141. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
  142. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
  143. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
  144. data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
  145. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
  146. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
  147. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
  148. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
  149. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
  150. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
  151. data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
  152. metadata +147 -12
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,93 @@
1
+ PATH
2
+ remote: /Users/joshuaclayton/dev/gems/factory_girl
3
+ specs:
4
+ factory_girl (3.0.0)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.0)
11
+ activesupport (= 3.2.0)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.0)
14
+ activemodel (= 3.2.0)
15
+ activesupport (= 3.2.0)
16
+ arel (~> 3.0.0)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.0)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ appraisal (0.3.8)
22
+ bundler
23
+ rake
24
+ arel (3.0.0)
25
+ aruba (0.4.6)
26
+ bcat (>= 0.6.1)
27
+ childprocess (>= 0.2.0)
28
+ cucumber (>= 1.0.2)
29
+ rdiscount (>= 1.6.8)
30
+ rspec (>= 2.6.0)
31
+ bcat (0.6.2)
32
+ rack (~> 1.0)
33
+ bluecloth (2.2.0)
34
+ bourne (1.0)
35
+ mocha (= 0.9.8)
36
+ builder (3.0.0)
37
+ childprocess (0.3.0)
38
+ ffi (~> 1.0.6)
39
+ cucumber (1.0.6)
40
+ builder (>= 2.1.2)
41
+ diff-lcs (>= 1.1.2)
42
+ gherkin (~> 2.4.18)
43
+ json (>= 1.4.6)
44
+ term-ansicolor (>= 1.0.6)
45
+ diff-lcs (1.1.3)
46
+ ffi (1.0.11)
47
+ gherkin (2.4.21)
48
+ json (>= 1.4.6)
49
+ i18n (0.6.0)
50
+ json (1.6.5)
51
+ mocha (0.9.8)
52
+ rake
53
+ multi_json (1.0.4)
54
+ rack (1.4.0)
55
+ rake (0.9.2.2)
56
+ rdiscount (1.6.8)
57
+ rspec (2.8.0)
58
+ rspec-core (~> 2.8.0)
59
+ rspec-expectations (~> 2.8.0)
60
+ rspec-mocks (~> 2.8.0)
61
+ rspec-core (2.8.0)
62
+ rspec-expectations (2.8.0)
63
+ diff-lcs (~> 1.1.2)
64
+ rspec-mocks (2.8.0)
65
+ simplecov (0.6.1)
66
+ multi_json (~> 1.0)
67
+ simplecov-html (~> 0.5.3)
68
+ simplecov-html (0.5.3)
69
+ sqlite3 (1.3.5)
70
+ sqlite3-ruby (1.3.3)
71
+ sqlite3 (>= 1.3.3)
72
+ term-ansicolor (1.0.7)
73
+ timecop (0.3.5)
74
+ tzinfo (0.3.31)
75
+ yard (0.7.4)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ activerecord (~> 3.2)
82
+ appraisal (~> 0.3.8)
83
+ aruba
84
+ bluecloth
85
+ bourne
86
+ cucumber (~> 1.0.0)
87
+ factory_girl!
88
+ mocha
89
+ rspec (~> 2.0)
90
+ simplecov
91
+ sqlite3-ruby
92
+ timecop
93
+ yard
@@ -0,0 +1,69 @@
1
+ require "active_support/core_ext/module/delegation"
2
+
3
+ require 'factory_girl/errors'
4
+ require 'factory_girl/factory_runner'
5
+ require 'factory_girl/strategy_calculator'
6
+ require 'factory_girl/strategy'
7
+ require 'factory_girl/registry'
8
+ require 'factory_girl/null_factory'
9
+ require 'factory_girl/null_object'
10
+ require 'factory_girl/factory'
11
+ require 'factory_girl/attribute_assigner'
12
+ require 'factory_girl/evaluator'
13
+ require 'factory_girl/evaluator_class_definer'
14
+ require 'factory_girl/attribute'
15
+ require 'factory_girl/callback'
16
+ require 'factory_girl/declaration_list'
17
+ require 'factory_girl/declaration'
18
+ require 'factory_girl/sequence'
19
+ require 'factory_girl/attribute_list'
20
+ require 'factory_girl/trait'
21
+ require 'factory_girl/aliases'
22
+ require 'factory_girl/definition'
23
+ require 'factory_girl/definition_proxy'
24
+ require 'factory_girl/syntax'
25
+ require 'factory_girl/find_definitions'
26
+ require 'factory_girl/reload'
27
+ require 'factory_girl/version'
28
+
29
+ module FactoryGirl
30
+ def self.factories
31
+ @factories ||= Registry.new("Factory")
32
+ end
33
+
34
+ def self.register_factory(factory)
35
+ factories.add(factory)
36
+ end
37
+
38
+ def self.factory_by_name(name)
39
+ factories.find(name)
40
+ end
41
+
42
+ def self.sequences
43
+ @sequences ||= Registry.new("Sequence")
44
+ end
45
+
46
+ def self.register_sequence(sequence)
47
+ sequences.add(sequence)
48
+ end
49
+
50
+ def self.sequence_by_name(name)
51
+ sequences.find(name)
52
+ end
53
+
54
+ def self.traits
55
+ @traits ||= Registry.new("Trait")
56
+ end
57
+
58
+ def self.register_trait(trait)
59
+ traits.add(trait)
60
+ end
61
+
62
+ def self.trait_by_name(name)
63
+ traits.find(name)
64
+ end
65
+
66
+ def self.callback_names
67
+ [:after_build, :after_create, :after_stub].freeze
68
+ end
69
+ end
@@ -0,0 +1,19 @@
1
+ module FactoryGirl
2
+ class << self
3
+ attr_accessor :aliases #:nodoc:
4
+ end
5
+
6
+ self.aliases = [
7
+ [/(.+)_id/, '\1'],
8
+ [/(.*)/, '\1_id']
9
+ ]
10
+
11
+ def self.aliases_for(attribute) #:nodoc:
12
+ aliases.collect do |params|
13
+ pattern, replace = *params
14
+ if pattern.match(attribute.to_s)
15
+ attribute.to_s.sub(pattern, replace).to_sym
16
+ end
17
+ end.compact << attribute
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ require "factory_girl/attribute/static"
2
+ require "factory_girl/attribute/dynamic"
3
+ require "factory_girl/attribute/association"
4
+ require "factory_girl/attribute/sequence"
5
+
6
+ module FactoryGirl
7
+
8
+ class Attribute #:nodoc:
9
+ attr_reader :name, :ignored
10
+
11
+ def initialize(name, ignored)
12
+ @name = name.to_sym
13
+ @ignored = ignored
14
+ ensure_non_attribute_writer!
15
+ end
16
+
17
+ def to_proc
18
+ lambda { }
19
+ end
20
+
21
+ def association?
22
+ false
23
+ end
24
+
25
+ def alias_for?(attr)
26
+ FactoryGirl.aliases_for(attr).include?(name)
27
+ end
28
+
29
+ private
30
+
31
+ def ensure_non_attribute_writer!
32
+ if @name.to_s =~ /=$/
33
+ attribute_name = $`
34
+ raise AttributeDefinitionError,
35
+ "factory_girl uses 'f.#{attribute_name} value' syntax " +
36
+ "rather than 'f.#{attribute_name} = value'"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module FactoryGirl
2
+ class Attribute #:nodoc:
3
+ class Association < Attribute #:nodoc:
4
+ attr_reader :factory
5
+
6
+ def initialize(name, factory, overrides)
7
+ super(name, false)
8
+ @factory = factory
9
+ @overrides = overrides
10
+ end
11
+
12
+ def to_proc
13
+ factory = @factory
14
+ overrides = @overrides
15
+ lambda { association(factory, overrides) }
16
+ end
17
+
18
+ def association?
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module FactoryGirl
2
+ class Attribute #:nodoc:
3
+ class Dynamic < Attribute #:nodoc:
4
+ def initialize(name, ignored, block)
5
+ super(name, ignored)
6
+ @block = block
7
+ end
8
+
9
+ def to_proc
10
+ block = @block
11
+
12
+ lambda {
13
+ value = block.arity == 1 ? block.call(self) : instance_exec(&block)
14
+ raise SequenceAbuseError if FactoryGirl::Sequence === value
15
+ value
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module FactoryGirl
2
+ class Attribute
3
+
4
+ class Sequence < Attribute
5
+ def initialize(name, sequence, ignored)
6
+ super(name, ignored)
7
+ @sequence = sequence
8
+ end
9
+
10
+ def to_proc
11
+ sequence = @sequence
12
+ lambda { FactoryGirl.generate(sequence) }
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module FactoryGirl
2
+ class Attribute #:nodoc:
3
+ class Static < Attribute #:nodoc:
4
+ def initialize(name, value, ignored)
5
+ super(name, ignored)
6
+ @value = value
7
+ end
8
+
9
+ def to_proc
10
+ value = @value
11
+ lambda { value }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,73 @@
1
+ module FactoryGirl
2
+ class AttributeAssigner
3
+ def initialize(evaluator, &instance_builder)
4
+ @instance_builder = instance_builder
5
+ @evaluator = evaluator
6
+ @attribute_list = evaluator.class.attribute_list
7
+ @attribute_names_assigned = []
8
+ end
9
+
10
+ def object
11
+ @evaluator.instance = build_class_instance
12
+ build_class_instance.tap do |instance|
13
+ attributes_to_set_on_instance.each do |attribute|
14
+ instance.send("#{attribute}=", get(attribute))
15
+ @attribute_names_assigned << attribute
16
+ end
17
+ end
18
+ end
19
+
20
+ def hash
21
+ @evaluator.instance = NullObject.new
22
+
23
+ attributes_to_set_on_hash.inject({}) do |result, attribute|
24
+ result[attribute] = get(attribute)
25
+ result
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def build_class_instance
32
+ @build_class_instance ||= @evaluator.instance_exec(&@instance_builder)
33
+ end
34
+
35
+ def get(attribute_name)
36
+ @evaluator.send(attribute_name)
37
+ end
38
+
39
+ def attributes_to_set_on_instance
40
+ (attribute_names_to_assign - @attribute_names_assigned).uniq
41
+ end
42
+
43
+ def attributes_to_set_on_hash
44
+ attribute_names_to_assign - association_names
45
+ end
46
+
47
+ def attribute_names_to_assign
48
+ non_ignored_attribute_names + override_names - ignored_attribute_names - alias_names_to_ignore
49
+ end
50
+
51
+ def non_ignored_attribute_names
52
+ @attribute_list.reject(&:ignored).map(&:name)
53
+ end
54
+
55
+ def ignored_attribute_names
56
+ @attribute_list.select(&:ignored).map(&:name)
57
+ end
58
+
59
+ def association_names
60
+ @attribute_list.associations.map(&:name)
61
+ end
62
+
63
+ def override_names
64
+ @evaluator.__overrides.keys
65
+ end
66
+
67
+ def alias_names_to_ignore
68
+ @attribute_list.reject(&:ignored).map do |attribute|
69
+ override_names.map {|override| attribute.name if attribute.alias_for?(override) && attribute.name != override && !ignored_attribute_names.include?(override) }
70
+ end.flatten.compact
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,54 @@
1
+ module FactoryGirl
2
+ class AttributeList
3
+ include Enumerable
4
+
5
+ def initialize(name = nil)
6
+ @name = name
7
+ @attributes = []
8
+ end
9
+
10
+ def define_attribute(attribute)
11
+ ensure_attribute_not_self_referencing! attribute
12
+ ensure_attribute_not_defined! attribute
13
+
14
+ add_attribute attribute
15
+ end
16
+
17
+ def each(&block)
18
+ @attributes.each(&block)
19
+ end
20
+
21
+ def associations
22
+ @attributes.select(&:association?)
23
+ end
24
+
25
+ def apply_attributes(attributes_to_apply)
26
+ attributes_to_apply.each {|attribute| add_attribute(attribute) }
27
+ end
28
+
29
+ private
30
+
31
+ def add_attribute(attribute)
32
+ @attributes << attribute
33
+ attribute
34
+ end
35
+
36
+ def ensure_attribute_not_defined!(attribute)
37
+ if attribute_defined?(attribute.name)
38
+ raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}"
39
+ end
40
+ end
41
+
42
+ def ensure_attribute_not_self_referencing!(attribute)
43
+ if attribute.respond_to?(:factory) && attribute.factory == @name
44
+ raise AssociationDefinitionError, "Self-referencing association '#{attribute.name}' in '#{attribute.factory}'"
45
+ end
46
+ end
47
+
48
+ def attribute_defined?(attribute_name)
49
+ @attributes.any? do |attribute|
50
+ attribute.name == attribute_name
51
+ end
52
+ end
53
+ end
54
+ end