gonzales 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/MIT-LICENSE +23 -0
  2. data/README.md +107 -0
  3. data/Rakefile +38 -0
  4. data/lib/gonzales/collection.rb +70 -0
  5. data/lib/gonzales/factories.rb +57 -0
  6. data/lib/gonzales/factory_girl/definition_proxy.rb +77 -0
  7. data/lib/gonzales/test_helper.rb +51 -0
  8. data/lib/gonzales/version.rb +3 -0
  9. data/lib/gonzales.rb +72 -0
  10. data/lib/tasks/gonzales_tasks.rake +7 -0
  11. data/test/dummy/README.rdoc +261 -0
  12. data/test/dummy/Rakefile +7 -0
  13. data/test/dummy/app/models/hat.rb +3 -0
  14. data/test/dummy/app/models/material.rb +3 -0
  15. data/test/dummy/app/models/outfit.rb +6 -0
  16. data/test/dummy/app/models/shoe.rb +6 -0
  17. data/test/dummy/app/models/wardrobe.rb +3 -0
  18. data/test/dummy/config/application.rb +59 -0
  19. data/test/dummy/config/boot.rb +10 -0
  20. data/test/dummy/config/database.yml +25 -0
  21. data/test/dummy/config/environment.rb +5 -0
  22. data/test/dummy/config/environments/development.rb +37 -0
  23. data/test/dummy/config/environments/production.rb +67 -0
  24. data/test/dummy/config/environments/test.rb +37 -0
  25. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  26. data/test/dummy/config/initializers/inflections.rb +15 -0
  27. data/test/dummy/config/initializers/mime_types.rb +5 -0
  28. data/test/dummy/config/initializers/secret_token.rb +7 -0
  29. data/test/dummy/config/initializers/session_store.rb +8 -0
  30. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/test/dummy/config/locales/en.yml +5 -0
  32. data/test/dummy/config/routes.rb +58 -0
  33. data/test/dummy/config.ru +4 -0
  34. data/test/dummy/db/development.sqlite3 +0 -0
  35. data/test/dummy/db/migrate/20121005205521_create_hats.rb +10 -0
  36. data/test/dummy/db/migrate/20121009054201_create_materials.rb +9 -0
  37. data/test/dummy/db/migrate/20121009055333_create_shoes.rb +16 -0
  38. data/test/dummy/db/migrate/20121009091652_create_outfits.rb +13 -0
  39. data/test/dummy/db/migrate/20121010161218_create_hats_outfits.rb +10 -0
  40. data/test/dummy/db/migrate/20121011131629_create_wardrobes.rb +9 -0
  41. data/test/dummy/db/migrate/20121011131724_add_wardrobe_to_outfit.rb +5 -0
  42. data/test/dummy/db/schema.rb +69 -0
  43. data/test/dummy/db/test.sqlite3 +0 -0
  44. data/test/dummy/log/development.log +571 -0
  45. data/test/dummy/log/test.log +20542 -0
  46. data/test/dummy/script/rails +6 -0
  47. data/test/dummy/test/factories/hats.rb +14 -0
  48. data/test/dummy/test/factories/materials.rb +11 -0
  49. data/test/dummy/test/factories/outfits.rb +16 -0
  50. data/test/dummy/test/factories/shoes.rb +16 -0
  51. data/test/dummy/test/factories/wardrobes.rb +7 -0
  52. data/test/dummy/test/speedy.rb +7 -0
  53. data/test/dummy/test/unit/hat_test.rb +14 -0
  54. data/test/dummy/test/unit/material_test.rb +7 -0
  55. data/test/dummy/test/unit/outfit_test.rb +36 -0
  56. data/test/dummy/test/unit/shoe_test.rb +13 -0
  57. data/test/dummy/test/unit/wardrobe_test.rb +7 -0
  58. data/test/dummy/tmp/speedy.yml +16 -0
  59. data/test/test_helper.rb +15 -0
  60. data/test/unit/gonzales/collection_test.rb +81 -0
  61. data/test/unit/gonzales/factories_test.rb +53 -0
  62. data/test/unit/gonzales/factory_girl/definition_proxy_test.rb +106 -0
  63. data/test/unit/gonzales/test_helper_test.rb +44 -0
  64. data/test/unit/gonzales_test.rb +15 -0
  65. metadata +251 -0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,14 @@
1
+ FactoryGirl.define do
2
+ factory :hat do
3
+ brim_type "Fat"
4
+ size 52
5
+ end
6
+ factory :sombrero, :class => 'Hat' do
7
+ brim_type "Narrow"
8
+ size 52
9
+ end
10
+ factory :stetson, :class => 'Hat' do
11
+ brim_type "Cool"
12
+ size 52
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :fabrick, :class => Material do
3
+ name "Fabrick"
4
+ end
5
+ factory :leader, :class => Material do
6
+ name "Leather"
7
+ end
8
+ factory :rubber, :class => Material do
9
+ name "Rubber"
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # Read about factories at http://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :outfit do
5
+ style "Mexican"
6
+ speedy :shoe, :boot
7
+ speedy :hat, :sombrero
8
+ alternative_hats { |outfit| [outfit.association(:stetson)] }
9
+ end
10
+ factory :girl_outfit, :class => Outfit do
11
+ style "Mexican"
12
+ speedy :shoe
13
+ speedy :hat
14
+ speedy :alternative_hats, :sombrero
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :shoe do
3
+ name 'Classy'
4
+ speedy :upper_material, :leader
5
+ speedy :lower_material, :rubber
6
+ speedy :inner_material, :leader
7
+ size 42
8
+ end
9
+ factory :boot, :class => 'Shoe' do
10
+ name 'Boot'
11
+ speedy :upper_material, :leader
12
+ speedy :lower_material, :leader
13
+ speedy :inner_material, :leader
14
+ size 42
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ # Read about factories at http://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :wardrobe do
5
+ name "MyString"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ Gonzales::Factories.load do |go|
2
+ go.speedy :hat
3
+ go.speedy :leader
4
+ go.speedy :fabrick
5
+ go.speedy :shoe
6
+ go.speedy :boot
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class HatTest < ActiveSupport::TestCase
4
+ setup do
5
+ Gonzales.initialize!
6
+ end
7
+ context 'loading hat' do
8
+ should 'not call factory' do
9
+ Factory.expects(:create).never
10
+ hat = speedy(:hat)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class MaterialTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ class OutfitTest < ActiveSupport::TestCase
4
+ setup do
5
+ Gonzales.initialize!
6
+ end
7
+ context 'loading outfit' do
8
+ should 'invoke factory for it and not for boot' do
9
+ Factory.expects(:create).with(:outfit)
10
+ outfit = speedy(:outfit)
11
+ end
12
+ should 'invoke factory for hat, but not for shoe' do
13
+ Hat.expects(:find).never
14
+ Shoe.expects(:find).once
15
+ outfit = speedy(:outfit)
16
+ assert_equal 'Narrow', outfit.hat.brim_type
17
+ end
18
+ end
19
+ context 'outfit' do
20
+ should 'have alternative thats association loaded' do
21
+ outfit = speedy(:outfit)
22
+ assert_equal 1, outfit.alternative_hats.size
23
+ assert_equal 'Cool', outfit.alternative_hats.first.brim_type
24
+ end
25
+ end
26
+ context 'exploring factory_girl' do
27
+ should 'explore possibilities' do
28
+ outfit = speedy(:girl_outfit)
29
+ assert_equal 'Fat', outfit.hat.brim_type
30
+ assert_equal 'Classy', outfit.shoe.name
31
+ assert_equal 1, outfit.alternative_hats.size
32
+ assert_equal 'Narrow', outfit.alternative_hats.first.brim_type
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class ShoeTest < ActiveSupport::TestCase
4
+ setup do
5
+ Gonzales.initialize!
6
+ end
7
+ context 'loading shoe' do
8
+ should 'not call factory' do
9
+ Factory.expects(:create).never
10
+ hat = speedy(:shoe)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class WardrobeTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ :hat:
3
+ :class: Hat
4
+ :id: 1
5
+ :leader:
6
+ :class: Material
7
+ :id: 1
8
+ :fabrick:
9
+ :class: Material
10
+ :id: 2
11
+ :shoe:
12
+ :class: Shoe
13
+ :id: 1
14
+ :boot:
15
+ :class: Shoe
16
+ :id: 2
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ Gonzales.configure do |config|
13
+ config.factory_module = Rails.root.join('test', 'dummy', 'tmp', 'speedy.yml')
14
+ config.factory_cache = Rails.root.join('test', 'dummy', 'test', 'speedy.rb')
15
+ end
@@ -0,0 +1,81 @@
1
+ # Copyright (c) 2012 Bingo Entreprenøren AS
2
+ # Copyright (c) 2012 Teknobingo Scandinavia AS
3
+ # Copyright (c) 2012 Knut I. Stenmark
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'test_helper'
25
+
26
+ class Gonzales::CollectionTest < ActiveSupport::TestCase
27
+
28
+ setup do
29
+ @coll = Gonzales::Collection
30
+ @entities = stub('entities')
31
+ @coll.stubs(:entities).returns(@entities)
32
+ end
33
+
34
+ context 'private method' do
35
+ context 'save' do
36
+ should 'save file immediately, since destructor is a unknown thing in ruby' do
37
+ @entities.expects(:to_yaml).returns('xyz')
38
+ file = stub('file')
39
+ File.expects(:open).with(Rails.root.join('tmp','speedy.yml'), 'w+').yields(file)
40
+ file.expects(:write).with('xyz')
41
+ @coll.send(:save)
42
+ end
43
+ end
44
+ context 'load' do
45
+ should 'load file from tmp' do
46
+ Gonzales.factory_cache = nil
47
+ YAML.expects(:load_file).with( Rails.root.join('tmp','speedy.yml'))
48
+ @coll.send(:load)
49
+ end
50
+ should 'handle that file does not exist' do
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'publich method' do
56
+ context 'add' do
57
+ should 'store entity' do
58
+ class Entity
59
+ def id
60
+ 5
61
+ end
62
+ end
63
+ @entities.expects(:[]=).with(:gonzales, :class => 'Gonzales::CollectionTest::Entity', :id => 5)
64
+ @coll.add(:gonzales, Entity.new)
65
+ end
66
+ end
67
+ context 'entity' do
68
+ should 'find record if it has been cached' do
69
+ Entity.expects(:find).with(2).returns(:midd)
70
+ @entities.expects(:[]).with(:entity).returns({:class => 'Gonzales::CollectionTest::Entity', :id => 2})
71
+ assert_equal :midd, @coll.entity(:entity)
72
+ end
73
+ should 'return nothing if not cached' do
74
+ Entity.expects(:find).never
75
+ @entities.expects(:[]).with(:entity).returns(nil)
76
+ assert_nil @coll.entity(:entity)
77
+ end
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2012 Bingo Entreprenøren AS
2
+ # Copyright (c) 2012 Teknobingo Scandinavia AS
3
+ # Copyright (c) 2012 Knut I. Stenmark
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'test_helper'
25
+
26
+ class Gonzales::FactoriesTest < ActiveSupport::TestCase
27
+
28
+ context 'speedy' do
29
+ should 'set collection to factory created by factory girl' do
30
+ Factory.expects(:create).with('panchos', {}).returns('hideaway')
31
+ Gonzales::Collection.expects(:add).with('panchos', 'hideaway').twice
32
+ Gonzales::Factories.speedy('panchos')
33
+ Factory.expects(:create).with('panchos', :merry => 'Melodies' ).returns('hideaway')
34
+ Gonzales::Factories.speedy('panchos', :merry => 'Melodies')
35
+ end
36
+ should 'support alias name' do
37
+ Factory.expects(:create).with('panchos', {}).returns('hideaway')
38
+ Gonzales::Collection.expects(:add).with('villa', 'hideaway').twice
39
+ Gonzales::Factories.speedy('villa', 'panchos')
40
+ Factory.expects(:create).with('panchos', :merry => 'Melodies' ).returns('hideaway')
41
+ Gonzales::Factories.speedy('villa','panchos', :merry => 'Melodies')
42
+ end
43
+ end
44
+
45
+ context 'load' do
46
+ should 'yield context' do
47
+ Gonzales::Collection.expects(:save).once
48
+ Gonzales::Factories.load do |context|
49
+ assert_equal Gonzales::Factories, context
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,106 @@
1
+ # Copyright (c) 2012 Bingo Entreprenøren AS
2
+ # Copyright (c) 2012 Teknobingo Scandinavia AS
3
+ # Copyright (c) 2012 Knut I. Stenmark
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'test_helper'
25
+
26
+ class Gonzales::FactoryGirl::DefinitionProxyTest < ActiveSupport::TestCase
27
+
28
+ class DefinitionProxyTest
29
+ include Gonzales::FactoryGirl::DefinitionProxy
30
+
31
+ attr_accessor :sylvester
32
+ attr_accessor :cartoons
33
+
34
+ def after_build
35
+ yield self
36
+ end
37
+ end
38
+
39
+ setup do
40
+ @proxy = DefinitionProxyTest.new
41
+ end
42
+
43
+
44
+ context 'speedy association' do
45
+ setup do
46
+ @proxy.sylvester = nil
47
+ @reflection = stub('reflection', :macro => :belongs_to)
48
+ end
49
+ should 'instantiate factory with default attribute' do
50
+ DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
51
+ Gonzales::Collection.expects(:entity).with(:sylvester).returns(nil)
52
+ Factory.expects(:create).with(:sylvester, {}).returns(:cat)
53
+ @proxy.speedy(:sylvester)
54
+ assert_equal :cat, @proxy.sylvester
55
+ end
56
+ should 'instantiate factory with defined attribute' do
57
+ DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
58
+ Gonzales::Collection.expects(:entity).with(:elmer).returns(nil)
59
+ Factory.expects(:create).with(:elmer, {}).returns(:cat)
60
+ @proxy.speedy(:sylvester, :elmer)
61
+ assert_equal :cat, @proxy.sylvester
62
+ end
63
+ should 'not try to instantiate factory or find entity from cache if attribute is set' do
64
+ DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
65
+ @proxy.sylvester = :already_set
66
+ Gonzales::Collection.expects(:entity).never
67
+ Factory.expects(:create).never
68
+ @proxy.speedy(:sylvester)
69
+ assert_equal :already_set, @proxy.sylvester
70
+ end
71
+ should 'load entity from cache if it is there' do
72
+ DefinitionProxyTest.expects(:reflect_on_association).with(:sylvester).returns(@reflection)
73
+ Gonzales::Collection.expects(:entity).with(:sylvester).returns(:cat)
74
+ Factory.expects(:create).never
75
+ @proxy.speedy(:sylvester)
76
+ assert_equal :cat, @proxy.sylvester
77
+ end
78
+ end
79
+
80
+ context 'speedy has_many and has_and_belongs_to_many association' do
81
+ setup do
82
+ @proxy.cartoons = []
83
+ end
84
+ should 'associate many elements as array' do
85
+ macro = :has_and_belongs_to_many
86
+ reflection = stub('reflection', :macro => macro)
87
+ DefinitionProxyTest.expects(:reflect_on_association).with(:cartoons).returns(reflection)
88
+ Gonzales::Collection.expects(:entity).with(:sylvester).returns(:cat)
89
+ Gonzales::Collection.expects(:entity).with(:elmer).returns(:man)
90
+ Factory.expects(:create).never
91
+ @proxy.speedy(:cartoons, :sylvester, :elmer)
92
+ assert_equal [:cat, :man], @proxy.cartoons, "Association failed for macro: #{macro}"
93
+ end
94
+ should 'not try to instantiate factory or find entity from cache if attribute is set' do
95
+ @proxy.cartoons = [:dog]
96
+ macro = :has_many
97
+ reflection = stub('reflection', :macro => macro)
98
+ DefinitionProxyTest.expects(:reflect_on_association).with(:cartoons).returns(reflection)
99
+ Gonzales::Collection.expects(:entity).never
100
+ Factory.expects(:create).never
101
+ @proxy.speedy(:cartoons, :sylvester)
102
+ assert_equal [:dog], @proxy.cartoons, "Association failed for macro: #{macro}"
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2012 Bingo Entreprenøren AS
2
+ # Copyright (c) 2012 Teknobingo Scandinavia AS
3
+ # Copyright (c) 2012 Knut I. Stenmark
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'test_helper'
25
+
26
+ class Gonzales::TestHelperTest < ActiveSupport::TestCase
27
+ include
28
+ context 'speedy' do
29
+ should 'return entity if cached' do
30
+ Gonzales::Collection.expects(:entity).with(:manolo).returns(:munoz)
31
+ assert_equal :munoz, speedy(:manolo)
32
+ end
33
+ should 'call factory if not cached' do
34
+ Gonzales::Collection.expects(:entity).with(:manolo).returns(nil)
35
+ Factory.expects(:create).with(:manolo).returns(:munoz)
36
+ assert_equal :munoz, speedy(:manolo)
37
+ end
38
+ should 'call factory with parameters if not cached' do
39
+ Gonzales::Collection.expects(:entity).with(:elmer).returns(nil)
40
+ Factory.expects(:create).with(:elmer, :fudd).returns(:midd)
41
+ assert_equal :midd, speedy(:elmer, :fudd)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class GonzalesTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Gonzales
6
+ end
7
+
8
+ context 'initializing' do
9
+ should 'load factory_file' do
10
+ Gonzales.factory_module = nil
11
+ Gonzales.expects(:load).with(Rails.root.join('test', 'speedy.rb'))
12
+ Gonzales.initialize!
13
+ end
14
+ end
15
+ end