challah 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -2
- data/README.md +18 -18
- data/lib/challah/test.rb +22 -5
- data/lib/challah/version.rb +1 -1
- data/test/audit_test.rb +32 -32
- data/test/controller_test.rb +9 -9
- data/test/cookie_store_test.rb +25 -25
- data/test/factories.rb +7 -7
- data/test/helper.rb +14 -12
- data/test/permission_test.rb +14 -14
- data/test/restrictions_controller_test.rb +29 -30
- data/test/role_test.rb +26 -26
- data/test/session_test.rb +65 -65
- data/test/sessions_controller_test.rb +13 -13
- data/test/simple_cookie_store_test.rb +25 -25
- data/test/user_test.rb +79 -79
- data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
- data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
- metadata +147 -12
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
share_examples_for "finds definitions" do
|
4
|
+
before do
|
5
|
+
FactoryGirl.stubs(:load)
|
6
|
+
FactoryGirl.find_definitions
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { FactoryGirl }
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec::Matchers.define :load_definitions_from do |file|
|
13
|
+
match do |given|
|
14
|
+
@has_received = have_received(:load).with(File.expand_path(file))
|
15
|
+
@has_received.matches?(given)
|
16
|
+
end
|
17
|
+
|
18
|
+
description do
|
19
|
+
"load definitions from #{file}"
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message_for_should do
|
23
|
+
@has_received.failure_message
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "definition loading" do
|
28
|
+
def self.in_directory_with_files(*files)
|
29
|
+
before do
|
30
|
+
@pwd = Dir.pwd
|
31
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
32
|
+
FileUtils.mkdir_p @tmp_dir
|
33
|
+
Dir.chdir(@tmp_dir)
|
34
|
+
|
35
|
+
files.each do |file|
|
36
|
+
FileUtils.mkdir_p File.dirname(file)
|
37
|
+
FileUtils.touch file
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
Dir.chdir(@pwd)
|
43
|
+
FileUtils.rm_rf(@tmp_dir)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "with factories.rb" do
|
48
|
+
in_directory_with_files 'factories.rb'
|
49
|
+
it_should_behave_like "finds definitions" do
|
50
|
+
it { should load_definitions_from('factories.rb') }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
%w(spec test).each do |dir|
|
55
|
+
describe "with a factories file under #{dir}" do
|
56
|
+
in_directory_with_files File.join(dir, 'factories.rb')
|
57
|
+
it_should_behave_like "finds definitions" do
|
58
|
+
it { should load_definitions_from("#{dir}/factories.rb") }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "with a factories file under #{dir}/factories" do
|
63
|
+
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb')
|
64
|
+
it_should_behave_like "finds definitions" do
|
65
|
+
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "with several factories files under #{dir}/factories" do
|
70
|
+
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb'),
|
71
|
+
File.join(dir, 'factories', 'person_factory.rb')
|
72
|
+
it_should_behave_like "finds definitions" do
|
73
|
+
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
74
|
+
it { should load_definitions_from("#{dir}/factories/person_factory.rb") }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "with several factories files under #{dir}/factories in non-alphabetical order" do
|
79
|
+
in_directory_with_files File.join(dir, 'factories', 'b.rb'),
|
80
|
+
File.join(dir, 'factories', 'a.rb')
|
81
|
+
it "loads the files in the right order" do
|
82
|
+
FactoryGirl.stubs(:load)
|
83
|
+
sorted_load_order = sequence("load order")
|
84
|
+
FactoryGirl.expects(:load).with(includes("a.rb")).in_sequence(sorted_load_order)
|
85
|
+
FactoryGirl.expects(:load).with(includes("b.rb")).in_sequence(sorted_load_order)
|
86
|
+
FactoryGirl.find_definitions
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "with nested and unnested factories files under #{dir}" do
|
91
|
+
in_directory_with_files File.join(dir, 'factories.rb'),
|
92
|
+
File.join(dir, 'factories', 'post_factory.rb'),
|
93
|
+
File.join(dir, 'factories', 'person_factory.rb')
|
94
|
+
it_should_behave_like "finds definitions" do
|
95
|
+
it { should load_definitions_from("#{dir}/factories.rb") }
|
96
|
+
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
97
|
+
it { should load_definitions_from("#{dir}/factories/person_factory.rb") }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "with deeply nested factory files under #{dir}" do
|
102
|
+
in_directory_with_files File.join(dir, 'factories', 'subdirectory', 'post_factory.rb'),
|
103
|
+
File.join(dir, 'factories', 'subdirectory', 'person_factory.rb')
|
104
|
+
it_should_behave_like "finds definitions" do
|
105
|
+
it { should load_definitions_from("#{dir}/factories/subdirectory/post_factory.rb") }
|
106
|
+
it { should load_definitions_from("#{dir}/factories/subdirectory/person_factory.rb") }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirl::NullFactory do
|
4
|
+
it { should delegate(:defined_traits).to(:definition) }
|
5
|
+
it { should delegate(:callbacks).to(:definition) }
|
6
|
+
it { should delegate(:attributes).to(:definition) }
|
7
|
+
it { should delegate(:constructor).to(:definition) }
|
8
|
+
|
9
|
+
its(:compile) { should be_nil }
|
10
|
+
its(:class_name) { should be_nil }
|
11
|
+
its(:attributes) { should be_an_instance_of(FactoryGirl::AttributeList) }
|
12
|
+
its(:evaluator_class) { should == FactoryGirl::Evaluator }
|
13
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::Registry do
|
4
|
+
let(:aliases) { [:thing, :widget] }
|
5
|
+
let(:sequence) { FactoryGirl::Sequence.new(:email) { |n| "somebody#{n}@example.com" } }
|
6
|
+
let(:factory) { FactoryGirl::Factory.new(:object) }
|
7
|
+
let(:other_factory) { FactoryGirl::Factory.new(:string) }
|
8
|
+
let(:factory_with_aliases) { FactoryGirl::Factory.new(:string, aliases: aliases) }
|
9
|
+
let(:registry_name) { "Factory" }
|
10
|
+
|
11
|
+
subject { FactoryGirl::Registry.new(registry_name) }
|
12
|
+
|
13
|
+
it { should be_kind_of(Enumerable) }
|
14
|
+
|
15
|
+
it "finds a registered a factory" do
|
16
|
+
subject.add(factory)
|
17
|
+
subject.find(factory.name).should == factory
|
18
|
+
end
|
19
|
+
|
20
|
+
it "raises when finding an unregistered factory" do
|
21
|
+
expect { subject.find(:bogus) }.to raise_error(ArgumentError, "Factory not registered: bogus")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "adds and returns a factory" do
|
25
|
+
subject.add(factory).should == factory
|
26
|
+
end
|
27
|
+
|
28
|
+
it "knows that a factory is registered by symbol" do
|
29
|
+
subject.add(factory)
|
30
|
+
subject.should be_registered(factory.name.to_sym)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "knows that a factory is registered by string" do
|
34
|
+
subject.add(factory)
|
35
|
+
subject.should be_registered(factory.name.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "knows that a factory isn't registered" do
|
39
|
+
subject.should_not be_registered("bogus")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can be accessed like a hash" do
|
43
|
+
subject.add(factory)
|
44
|
+
subject[factory.name].should == factory
|
45
|
+
end
|
46
|
+
|
47
|
+
it "iterates registered factories" do
|
48
|
+
subject.add(factory)
|
49
|
+
subject.add(other_factory)
|
50
|
+
subject.to_a.should =~ [factory, other_factory]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "iterates registered factories uniquely with aliases" do
|
54
|
+
subject.add(factory)
|
55
|
+
subject.add(factory_with_aliases)
|
56
|
+
subject.to_a.should =~ [factory, factory_with_aliases]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "registers an sequence" do
|
60
|
+
subject.add(sequence)
|
61
|
+
subject.find(:email).should == sequence
|
62
|
+
end
|
63
|
+
|
64
|
+
it "doesn't allow a duplicate name" do
|
65
|
+
expect { 2.times { subject.add(factory) } }.
|
66
|
+
to raise_error(FactoryGirl::DuplicateDefinitionError, "Factory already registered: object")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "registers aliases" do
|
70
|
+
subject.add(factory_with_aliases)
|
71
|
+
aliases.each do |name|
|
72
|
+
subject.find(name).should == factory_with_aliases
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "clears registered factories" do
|
77
|
+
subject.add(factory)
|
78
|
+
subject.clear
|
79
|
+
subject.count.should be_zero
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::Sequence do
|
4
|
+
describe "a basic sequence" do
|
5
|
+
let(:name) { :test }
|
6
|
+
subject { FactoryGirl::Sequence.new(name) {|n| "=#{n}" } }
|
7
|
+
|
8
|
+
its(:name) { should == name }
|
9
|
+
its(:names) { should == [name] }
|
10
|
+
its(:next) { should == "=1" }
|
11
|
+
|
12
|
+
describe "when incrementing" do
|
13
|
+
before { subject.next }
|
14
|
+
its(:next) { should == "=2" }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "a custom sequence" do
|
19
|
+
subject { FactoryGirl::Sequence.new(:name, "A") {|n| "=#{n}" } }
|
20
|
+
its(:next) { should == "=A" }
|
21
|
+
|
22
|
+
describe "when incrementing" do
|
23
|
+
before { subject.next }
|
24
|
+
its(:next) { should == "=B" }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "a basic sequence without a block" do
|
29
|
+
subject { FactoryGirl::Sequence.new(:name) }
|
30
|
+
its(:next) { should == 1 }
|
31
|
+
|
32
|
+
describe "when incrementing" do
|
33
|
+
before { subject.next }
|
34
|
+
its(:next) { should == 2 }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "a custom sequence without a block" do
|
39
|
+
subject { FactoryGirl::Sequence.new(:name, "A") }
|
40
|
+
its(:next) { should == "A" }
|
41
|
+
|
42
|
+
describe "when incrementing" do
|
43
|
+
before { subject.next }
|
44
|
+
its(:next) { should == "B" }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::Strategy::AttributesFor do
|
4
|
+
let(:result) { { name: "John Doe", gender: "Male", admin: false } }
|
5
|
+
let(:attribute_assigner) { stub("attribute assigner", hash: result) }
|
6
|
+
|
7
|
+
it_should_behave_like "strategy without association support"
|
8
|
+
|
9
|
+
it "returns the hash from the attribute assigner" do
|
10
|
+
subject.result(attribute_assigner, lambda {|item| item }).should == result
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not run the to_create block" do
|
14
|
+
expect do
|
15
|
+
subject.result(attribute_assigner, lambda {|item| raise "failed" })
|
16
|
+
end.to_not raise_error
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirl::Strategy::Build do
|
4
|
+
it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create
|
5
|
+
it_should_behave_like "strategy with callbacks", :after_build
|
6
|
+
it_should_behave_like "strategy with strategy: :build", FactoryGirl::Strategy::Build
|
7
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::Strategy::Create do
|
4
|
+
it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Create
|
5
|
+
it_should_behave_like "strategy with callbacks", :after_build, :after_create
|
6
|
+
|
7
|
+
it "runs a custom create block" do
|
8
|
+
block_run = false
|
9
|
+
block = lambda {|instance| block_run = true }
|
10
|
+
subject.result(stub("assigner", object: stub("result instance")), block)
|
11
|
+
block_run.should be_true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::Strategy::Stub do
|
4
|
+
it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Stub
|
5
|
+
it_should_behave_like "strategy with callbacks", :after_stub
|
6
|
+
it_should_behave_like "strategy with strategy: :build", FactoryGirl::Strategy::Stub
|
7
|
+
|
8
|
+
context "asking for a result" do
|
9
|
+
before { Timecop.freeze(Time.now) }
|
10
|
+
after { Timecop.return }
|
11
|
+
let(:result_instance) do
|
12
|
+
define_class("ResultInstance") do
|
13
|
+
attr_accessor :id
|
14
|
+
end.new
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:assigner) { stub("attribute assigner", object: result_instance) }
|
18
|
+
let(:to_create) { lambda {|instance| instance } }
|
19
|
+
|
20
|
+
it { subject.result(assigner, to_create).should_not be_new_record }
|
21
|
+
it { subject.result(assigner, to_create).should be_persisted }
|
22
|
+
|
23
|
+
it "assigns created_at" do
|
24
|
+
created_at = subject.result(assigner, to_create).created_at
|
25
|
+
created_at.should == Time.now
|
26
|
+
|
27
|
+
Timecop.travel(150000)
|
28
|
+
|
29
|
+
subject.result(assigner, to_create).created_at.should == created_at
|
30
|
+
end
|
31
|
+
|
32
|
+
[:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
|
33
|
+
it "raises when attempting to connect to the database by calling #{database_method}" do
|
34
|
+
expect do
|
35
|
+
subject.result(assigner, to_create).send(database_method)
|
36
|
+
end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirl::StrategyCalculator, "with a FactoryGirl::Strategy object" do
|
4
|
+
let(:strategy) { FactoryGirl::Strategy::Build }
|
5
|
+
|
6
|
+
it "returns the strategy object" do
|
7
|
+
FactoryGirl::StrategyCalculator.new(strategy).strategy.should == strategy
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe FactoryGirl::StrategyCalculator, "with a non-FactoryGirl::Strategy object" do
|
12
|
+
before { define_class "MyAwesomeStrategy" }
|
13
|
+
|
14
|
+
let(:strategy) { MyAwesomeStrategy }
|
15
|
+
|
16
|
+
it "returns the strategy object" do
|
17
|
+
expect { FactoryGirl::StrategyCalculator.new(strategy).strategy }.to raise_error "unrecognized method MyAwesomeStrategy"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe FactoryGirl::StrategyCalculator do
|
22
|
+
it "returns the correct strategy object for :build" do
|
23
|
+
FactoryGirl::StrategyCalculator.new(:build).strategy.should == FactoryGirl::Strategy::Build
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the correct strategy object for :create" do
|
27
|
+
FactoryGirl::StrategyCalculator.new(:create).strategy.should == FactoryGirl::Strategy::Create
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises when passing a bogus strategy" do
|
31
|
+
expect { FactoryGirl::StrategyCalculator.new(:bogus_strategy).strategy }.to raise_error "unrecognized method bogus_strategy"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::Strategy do
|
4
|
+
it "raises an error when asking for the result" do
|
5
|
+
expect { subject.result(stub("assigner"), lambda {|instance| instance }) }.to raise_error(NotImplementedError, "Strategies must return a result")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "raises an error when asking for the association" do
|
9
|
+
expect { subject.association(stub("runner")) }.to raise_error(NotImplementedError, "Strategies must return an association")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe FactoryGirl::Strategy, ".ensure_strategy_exists!" do
|
14
|
+
it "raises when passed a nonexistent strategy" do
|
15
|
+
expect { FactoryGirl::Strategy.ensure_strategy_exists!(:nonexistent) }.to raise_error(ArgumentError, "Unknown strategy: nonexistent")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "doesn't raise when passed a valid strategy" do
|
19
|
+
expect { FactoryGirl::Strategy.ensure_strategy_exists!(:create) }.to_not raise_error
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirl do
|
4
|
+
let(:factory) { FactoryGirl::Factory.new(:object) }
|
5
|
+
let(:sequence) { FactoryGirl::Sequence.new(:email) }
|
6
|
+
let(:trait) { FactoryGirl::Trait.new(:admin) }
|
7
|
+
|
8
|
+
it "finds a registered factory" do
|
9
|
+
FactoryGirl.register_factory(factory)
|
10
|
+
FactoryGirl.factory_by_name(factory.name).should == factory
|
11
|
+
end
|
12
|
+
|
13
|
+
it "finds a registered sequence" do
|
14
|
+
FactoryGirl.register_sequence(sequence)
|
15
|
+
FactoryGirl.sequence_by_name(sequence.name).should == sequence
|
16
|
+
end
|
17
|
+
|
18
|
+
it "finds a registered trait" do
|
19
|
+
FactoryGirl.register_trait(trait)
|
20
|
+
FactoryGirl.trait_by_name(trait.name).should == trait
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
|
8
|
+
require "simplecov"
|
9
|
+
SimpleCov.start
|
10
|
+
|
11
|
+
require 'factory_girl'
|
12
|
+
require "mocha"
|
13
|
+
require "bourne"
|
14
|
+
require "timecop"
|
15
|
+
|
16
|
+
Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.mock_framework = :mocha
|
20
|
+
|
21
|
+
config.include DeclarationMatchers
|
22
|
+
|
23
|
+
config.after do
|
24
|
+
FactoryGirl.reload
|
25
|
+
end
|
26
|
+
end
|