johnsbrn-has_many_polymorphs 2.13

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 (174) hide show
  1. data/CHANGELOG +84 -0
  2. data/LICENSE +184 -0
  3. data/Manifest +174 -0
  4. data/README +205 -0
  5. data/TODO +2 -0
  6. data/examples/hmph.rb +69 -0
  7. data/generators/tagging/tagging_generator.rb +97 -0
  8. data/generators/tagging/templates/migration.rb +28 -0
  9. data/generators/tagging/templates/tag.rb +39 -0
  10. data/generators/tagging/templates/tag_test.rb +15 -0
  11. data/generators/tagging/templates/tagging.rb +16 -0
  12. data/generators/tagging/templates/tagging_extensions.rb +159 -0
  13. data/generators/tagging/templates/tagging_test.rb +85 -0
  14. data/generators/tagging/templates/taggings.yml +23 -0
  15. data/generators/tagging/templates/tags.yml +7 -0
  16. data/has_many_polymorphs.gemspec +100 -0
  17. data/init.rb +2 -0
  18. data/lib/has_many_polymorphs.rb +27 -0
  19. data/lib/has_many_polymorphs/association.rb +159 -0
  20. data/lib/has_many_polymorphs/autoload.rb +70 -0
  21. data/lib/has_many_polymorphs/base.rb +60 -0
  22. data/lib/has_many_polymorphs/class_methods.rb +600 -0
  23. data/lib/has_many_polymorphs/configuration.rb +19 -0
  24. data/lib/has_many_polymorphs/debugging_tools.rb +103 -0
  25. data/lib/has_many_polymorphs/rake_task_redefine_task.rb +35 -0
  26. data/lib/has_many_polymorphs/reflection.rb +58 -0
  27. data/lib/has_many_polymorphs/support_methods.rb +84 -0
  28. data/test/fixtures/bow_wows.yml +10 -0
  29. data/test/fixtures/cats.yml +18 -0
  30. data/test/fixtures/eaters_foodstuffs.yml +0 -0
  31. data/test/fixtures/fish.yml +12 -0
  32. data/test/fixtures/frogs.yml +5 -0
  33. data/test/fixtures/keep_your_enemies_close.yml +0 -0
  34. data/test/fixtures/little_whale_pupils.yml +0 -0
  35. data/test/fixtures/people.yml +7 -0
  36. data/test/fixtures/petfoods.yml +11 -0
  37. data/test/fixtures/whales.yml +5 -0
  38. data/test/fixtures/wild_boars.yml +10 -0
  39. data/test/generator/tagging_generator_test.rb +42 -0
  40. data/test/integration/app/README +182 -0
  41. data/test/integration/app/Rakefile +19 -0
  42. data/test/integration/app/app/controllers/application.rb +7 -0
  43. data/test/integration/app/app/controllers/bones_controller.rb +5 -0
  44. data/test/integration/app/app/helpers/addresses_helper.rb +2 -0
  45. data/test/integration/app/app/helpers/application_helper.rb +3 -0
  46. data/test/integration/app/app/helpers/bones_helper.rb +2 -0
  47. data/test/integration/app/app/helpers/sellers_helper.rb +28 -0
  48. data/test/integration/app/app/helpers/states_helper.rb +2 -0
  49. data/test/integration/app/app/helpers/users_helper.rb +2 -0
  50. data/test/integration/app/app/models/bone.rb +2 -0
  51. data/test/integration/app/app/models/double_sti_parent.rb +2 -0
  52. data/test/integration/app/app/models/double_sti_parent_relationship.rb +2 -0
  53. data/test/integration/app/app/models/organic_substance.rb +2 -0
  54. data/test/integration/app/app/models/single_sti_parent.rb +4 -0
  55. data/test/integration/app/app/models/single_sti_parent_relationship.rb +4 -0
  56. data/test/integration/app/app/models/stick.rb +2 -0
  57. data/test/integration/app/app/models/stone.rb +2 -0
  58. data/test/integration/app/app/views/addresses/edit.html.erb +12 -0
  59. data/test/integration/app/app/views/addresses/index.html.erb +18 -0
  60. data/test/integration/app/app/views/addresses/new.html.erb +11 -0
  61. data/test/integration/app/app/views/addresses/show.html.erb +3 -0
  62. data/test/integration/app/app/views/bones/index.rhtml +5 -0
  63. data/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
  64. data/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
  65. data/test/integration/app/app/views/layouts/states.html.erb +17 -0
  66. data/test/integration/app/app/views/layouts/users.html.erb +17 -0
  67. data/test/integration/app/app/views/sellers/edit.html.erb +12 -0
  68. data/test/integration/app/app/views/sellers/index.html.erb +20 -0
  69. data/test/integration/app/app/views/sellers/new.html.erb +11 -0
  70. data/test/integration/app/app/views/sellers/show.html.erb +3 -0
  71. data/test/integration/app/app/views/states/edit.html.erb +12 -0
  72. data/test/integration/app/app/views/states/index.html.erb +19 -0
  73. data/test/integration/app/app/views/states/new.html.erb +11 -0
  74. data/test/integration/app/app/views/states/show.html.erb +3 -0
  75. data/test/integration/app/app/views/users/edit.html.erb +12 -0
  76. data/test/integration/app/app/views/users/index.html.erb +22 -0
  77. data/test/integration/app/app/views/users/new.html.erb +11 -0
  78. data/test/integration/app/app/views/users/show.html.erb +3 -0
  79. data/test/integration/app/config/boot.rb +110 -0
  80. data/test/integration/app/config/database.yml +17 -0
  81. data/test/integration/app/config/environment.rb +19 -0
  82. data/test/integration/app/config/environment.rb.canonical +19 -0
  83. data/test/integration/app/config/environments/development.rb +8 -0
  84. data/test/integration/app/config/environments/production.rb +18 -0
  85. data/test/integration/app/config/environments/test.rb +19 -0
  86. data/test/integration/app/config/locomotive.yml +6 -0
  87. data/test/integration/app/config/routes.rb +33 -0
  88. data/test/integration/app/config/ultrasphinx/default.base +56 -0
  89. data/test/integration/app/config/ultrasphinx/development.conf.canonical +155 -0
  90. data/test/integration/app/db/migrate/001_create_sticks.rb +11 -0
  91. data/test/integration/app/db/migrate/002_create_stones.rb +11 -0
  92. data/test/integration/app/db/migrate/003_create_organic_substances.rb +11 -0
  93. data/test/integration/app/db/migrate/004_create_bones.rb +8 -0
  94. data/test/integration/app/db/migrate/005_create_single_sti_parents.rb +11 -0
  95. data/test/integration/app/db/migrate/006_create_double_sti_parents.rb +11 -0
  96. data/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb +13 -0
  97. data/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb +14 -0
  98. data/test/integration/app/db/migrate/009_create_library_model.rb +11 -0
  99. data/test/integration/app/doc/README_FOR_APP +2 -0
  100. data/test/integration/app/generators/commenting_generator_test.rb +83 -0
  101. data/test/integration/app/lib/library_model.rb +2 -0
  102. data/test/integration/app/public/404.html +30 -0
  103. data/test/integration/app/public/500.html +30 -0
  104. data/test/integration/app/public/dispatch.cgi +10 -0
  105. data/test/integration/app/public/dispatch.fcgi +24 -0
  106. data/test/integration/app/public/dispatch.rb +10 -0
  107. data/test/integration/app/public/favicon.ico +0 -0
  108. data/test/integration/app/public/images/rails.png +0 -0
  109. data/test/integration/app/public/index.html +277 -0
  110. data/test/integration/app/public/javascripts/application.js +2 -0
  111. data/test/integration/app/public/javascripts/controls.js +833 -0
  112. data/test/integration/app/public/javascripts/dragdrop.js +942 -0
  113. data/test/integration/app/public/javascripts/effects.js +1088 -0
  114. data/test/integration/app/public/javascripts/prototype.js +2515 -0
  115. data/test/integration/app/public/robots.txt +1 -0
  116. data/test/integration/app/public/stylesheets/scaffold.css +74 -0
  117. data/test/integration/app/script/about +3 -0
  118. data/test/integration/app/script/breakpointer +3 -0
  119. data/test/integration/app/script/console +3 -0
  120. data/test/integration/app/script/destroy +3 -0
  121. data/test/integration/app/script/generate +3 -0
  122. data/test/integration/app/script/performance/benchmarker +3 -0
  123. data/test/integration/app/script/performance/profiler +3 -0
  124. data/test/integration/app/script/plugin +3 -0
  125. data/test/integration/app/script/process/inspector +3 -0
  126. data/test/integration/app/script/process/reaper +3 -0
  127. data/test/integration/app/script/process/spawner +3 -0
  128. data/test/integration/app/script/runner +3 -0
  129. data/test/integration/app/script/server +3 -0
  130. data/test/integration/app/test/fixtures/double_sti_parent_relationships.yml +7 -0
  131. data/test/integration/app/test/fixtures/double_sti_parents.yml +7 -0
  132. data/test/integration/app/test/fixtures/organic_substances.yml +5 -0
  133. data/test/integration/app/test/fixtures/single_sti_parent_relationships.yml +7 -0
  134. data/test/integration/app/test/fixtures/single_sti_parents.yml +7 -0
  135. data/test/integration/app/test/fixtures/sticks.yml +7 -0
  136. data/test/integration/app/test/fixtures/stones.yml +7 -0
  137. data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
  138. data/test/integration/app/test/functional/bones_controller_test.rb +8 -0
  139. data/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
  140. data/test/integration/app/test/functional/states_controller_test.rb +57 -0
  141. data/test/integration/app/test/functional/users_controller_test.rb +57 -0
  142. data/test/integration/app/test/test_helper.rb +8 -0
  143. data/test/integration/app/test/unit/bone_test.rb +8 -0
  144. data/test/integration/app/test/unit/double_sti_parent_relationship_test.rb +8 -0
  145. data/test/integration/app/test/unit/double_sti_parent_test.rb +8 -0
  146. data/test/integration/app/test/unit/organic_substance_test.rb +8 -0
  147. data/test/integration/app/test/unit/single_sti_parent_relationship_test.rb +8 -0
  148. data/test/integration/app/test/unit/single_sti_parent_test.rb +8 -0
  149. data/test/integration/app/test/unit/stick_test.rb +8 -0
  150. data/test/integration/app/test/unit/stone_test.rb +8 -0
  151. data/test/integration/server_test.rb +43 -0
  152. data/test/models/aquatic/fish.rb +5 -0
  153. data/test/models/aquatic/pupils_whale.rb +7 -0
  154. data/test/models/aquatic/whale.rb +15 -0
  155. data/test/models/beautiful_fight_relationship.rb +26 -0
  156. data/test/models/canine.rb +9 -0
  157. data/test/models/cat.rb +5 -0
  158. data/test/models/dog.rb +18 -0
  159. data/test/models/eaters_foodstuff.rb +10 -0
  160. data/test/models/frog.rb +4 -0
  161. data/test/models/kitten.rb +3 -0
  162. data/test/models/parentship.rb +4 -0
  163. data/test/models/person.rb +9 -0
  164. data/test/models/petfood.rb +39 -0
  165. data/test/models/tabby.rb +2 -0
  166. data/test/models/wild_boar.rb +3 -0
  167. data/test/modules/extension_module.rb +9 -0
  168. data/test/modules/other_extension_module.rb +9 -0
  169. data/test/patches/symlinked_plugins_1.2.6.diff +46 -0
  170. data/test/schema.rb +87 -0
  171. data/test/setup.rb +14 -0
  172. data/test/test_helper.rb +51 -0
  173. data/test/unit/has_many_polymorphs_test.rb +714 -0
  174. metadata +237 -0
@@ -0,0 +1,19 @@
1
+
2
+ =begin rdoc
3
+ Access the <tt>has_many_polymorphs_options</tt> hash in your Rails::Initializer.run#after_initialize block if you need to modify the behavior of Rails::Initializer::HasManyPolymorphsAutoload.
4
+ =end
5
+
6
+ module Rails #:nodoc:
7
+ class Configuration
8
+
9
+ def has_many_polymorphs_options
10
+ ::HasManyPolymorphs.options
11
+ end
12
+
13
+ def has_many_polymorphs_options=(hash)
14
+ ::HasManyPolymorphs.options = HashWithIndifferentAccess.new(hash)
15
+ end
16
+
17
+ end
18
+ end
19
+
@@ -0,0 +1,103 @@
1
+
2
+ =begin rdoc
3
+
4
+ Debugging tools for Has_many_polymorphs.
5
+
6
+ Enable the different tools by setting the environment variable HMP_DEBUG. Settings with special meaning are <tt>"ruby-debug"</tt>, <tt>"trace"</tt>, and <tt>"dependencies"</tt>.
7
+
8
+ == Code generation
9
+
10
+ Enabled by default when HMP_DEBUG is set.
11
+
12
+ Ouputs a folder <tt>generated_models/</tt> in RAILS_ROOT containing valid Ruby files explaining all the ActiveRecord relationships set up by the plugin, as well as listing the line in the plugin that called each particular association method.
13
+
14
+ == Ruby-debug
15
+
16
+ Enable by setting HMP_DEBUG to <tt>"ruby-debug"</tt>.
17
+
18
+ Starts <tt>ruby-debug</tt> for the life of the process.
19
+
20
+ == Trace
21
+
22
+ Enable by setting HMP_DEBUG to <tt>"ruby-debug"</tt>.
23
+
24
+ Outputs an indented trace of relevant method calls as they occur.
25
+
26
+ == Dependencies
27
+
28
+ Enable by setting HMP_DEBUG to <tt>"dependencies"</tt>.
29
+
30
+ Turns on Rails' default dependency logging.
31
+
32
+ =end
33
+
34
+ _logger_warn "debug mode enabled"
35
+
36
+ class << ActiveRecord::Base
37
+ COLLECTION_METHODS = [:belongs_to, :has_many, :has_and_belongs_to_many, :has_one,
38
+ :has_many_polymorphs, :acts_as_double_polymorphic_join].each do |method_name|
39
+ alias_method "original_#{method_name}".to_sym, method_name
40
+ undef_method method_name
41
+ end
42
+
43
+ unless defined? GENERATED_CODE_DIR
44
+ GENERATED_CODE_DIR = "#{RAILS_ROOT}/generated_models"
45
+
46
+ begin
47
+ system "rm -rf #{GENERATED_CODE_DIR}"
48
+ Dir.mkdir GENERATED_CODE_DIR
49
+ rescue Errno::EACCES
50
+ _logger_warn "no permissions for generated code dir: #{GENERATED_CODE_DIR}"
51
+ end
52
+
53
+ if File.exist? GENERATED_CODE_DIR
54
+ alias :original_method_missing :method_missing
55
+ def method_missing(method_name, *args, &block)
56
+ if COLLECTION_METHODS.include? method_name.to_sym
57
+ Dir.chdir GENERATED_CODE_DIR do
58
+ filename = "#{demodulate(self.name.underscore)}.rb"
59
+ contents = File.open(filename).read rescue "\nclass #{self.name}\n\nend\n"
60
+ line = caller[1][/\:(\d+)\:/, 1]
61
+ contents[-5..-5] = "\n #{method_name} #{args[0..-2].inspect[1..-2]},\n #{args[-1].inspect[1..-2].gsub(" :", "\n :").gsub("=>", " => ")}\n#{ block ? " #{block.inspect.sub(/\@.*\//, '@')}\n" : ""} # called from line #{line}\n\n"
62
+ File.open(filename, "w") do |file|
63
+ file.puts contents
64
+ end
65
+ end
66
+ # doesn't actually display block contents
67
+ self.send("original_#{method_name}", *args, &block)
68
+ else
69
+ self.send(:original_method_missing, method_name, *args, &block)
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+
77
+ case ENV['HMP_DEBUG']
78
+
79
+ when "ruby-debug"
80
+ require 'rubygems'
81
+ require 'ruby-debug'
82
+ Debugger.start
83
+ _logger_warn "ruby-debug enabled."
84
+
85
+ when "trace"
86
+ _logger_warn "method tracing enabled"
87
+ $debug_trace_indent = 0
88
+ set_trace_func (proc do |event, file, line, id, binding, classname|
89
+ if id.to_s =~ /instantiate/ #/IRB|Wirble|RubyLex|RubyToken|Logger|ConnectionAdapters|SQLite3|MonitorMixin|Benchmark|Inflector|Inflections/
90
+ if event == 'call'
91
+ puts (" " * $debug_trace_indent) + "#{event}ed #{classname}\##{id} from #{file.split('/').last}::#{line}"
92
+ $debug_trace_indent += 1
93
+ elsif event == 'return'
94
+ $debug_trace_indent -= 1 unless $debug_trace_indent == 0
95
+ puts (" " * $debug_trace_indent) + "#{event}ed #{classname}\##{id}"
96
+ end
97
+ end
98
+ end)
99
+
100
+ when "dependencies"
101
+ _logger_warn "dependency activity being logged"
102
+ (::Dependencies.log_activity = true) rescue nil
103
+ end
@@ -0,0 +1,35 @@
1
+
2
+ # Redefine instead of chain a Rake task
3
+ # http://www.bigbold.com/snippets/posts/show/2032
4
+
5
+ module Rake
6
+ module TaskManager
7
+ def redefine_task(task_class, args, &block)
8
+ task_name, deps = resolve_args(args)
9
+ task_name = task_class.scope_name(@scope, task_name)
10
+ deps = [deps] unless deps.respond_to?(:to_ary)
11
+ deps = deps.collect {|d| d.to_s }
12
+ task = @tasks[task_name.to_s] = task_class.new(task_name, self)
13
+ task.application = self
14
+ task.add_comment(@last_comment)
15
+ @last_comment = nil
16
+ task.enhance(deps, &block)
17
+ task
18
+ end
19
+ end
20
+ class Task
21
+ class << self
22
+ def redefine_task(args, &block)
23
+ Rake.application.redefine_task(self, args, &block)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ class Object
30
+ def silently
31
+ stderr, stdout, $stderr, $stdout = $stderr, $stdout, StringIO.new, StringIO.new
32
+ yield
33
+ $stderr, $stdout = stderr, stdout
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ module ActiveRecord #:nodoc:
2
+ module Reflection #:nodoc:
3
+
4
+ module ClassMethods #:nodoc:
5
+
6
+ # Update the default reflection switch so that <tt>:has_many_polymorphs</tt> types get instantiated.
7
+ # It's not a composed method so we have to override the whole thing.
8
+ def create_reflection(macro, name, options, active_record)
9
+ case macro
10
+ when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
11
+ klass = options[:through] ? ThroughReflection : AssociationReflection
12
+ reflection = klass.new(macro, name, options, active_record)
13
+ when :composed_of
14
+ reflection = AggregateReflection.new(macro, name, options, active_record)
15
+ # added by has_many_polymorphs #
16
+ when :has_many_polymorphs
17
+ reflection = PolymorphicReflection.new(macro, name, options, active_record)
18
+ end
19
+ write_inheritable_hash :reflections, name => reflection
20
+ reflection
21
+ end
22
+
23
+ end
24
+
25
+ class PolymorphicError < ActiveRecordError #:nodoc:
26
+ end
27
+
28
+ =begin rdoc
29
+
30
+ The reflection built by the <tt>has_many_polymorphs</tt> method.
31
+
32
+ Inherits from ActiveRecord::Reflection::AssociationReflection.
33
+
34
+ =end
35
+
36
+ class PolymorphicReflection < ThroughReflection
37
+ # Stub out the validity check. Has_many_polymorphs checks validity on macro creation, not on reflection.
38
+ def check_validity!
39
+ # nothing
40
+ end
41
+
42
+ # Return the source reflection.
43
+ def source_reflection
44
+ # normally is the has_many to the through model, but we return ourselves,
45
+ # since there isn't a real source class for a polymorphic target
46
+ self
47
+ end
48
+
49
+ # Set the classname of the target. Uses the join class name.
50
+ def class_name
51
+ # normally is the classname of the association target
52
+ @class_name ||= options[:join_class_name]
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,84 @@
1
+
2
+ class String
3
+
4
+ # Changes an underscored string into a class reference.
5
+ def _as_class
6
+ # classify expects self to be plural
7
+ self.classify.constantize
8
+ end
9
+
10
+ # For compatibility with the Symbol extensions.
11
+ alias :_singularize :singularize
12
+ alias :_pluralize :pluralize
13
+ alias :_classify :classify
14
+ end
15
+
16
+ class Symbol
17
+
18
+ # Changes an underscored symbol into a class reference.
19
+ def _as_class; self.to_s._as_class; end
20
+
21
+ # Changes a plural symbol into a singular symbol.
22
+ def _singularize; self.to_s.singularize.to_sym; end
23
+
24
+ # Changes a singular symbol into a plural symbol.
25
+ def _pluralize; self.to_s.pluralize.to_sym; end
26
+
27
+ # Changes a symbol into a class name string.
28
+ def _classify; self.to_s.classify; end
29
+ end
30
+
31
+ class Array
32
+
33
+ # Flattens the first level of self.
34
+ def _flatten_once
35
+ self.inject([]){|r, el| r + Array(el)}
36
+ end
37
+
38
+ # Rails 1.2.3 compatibility method. Copied from http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb?rev=7217
39
+ def _extract_options!
40
+ last.is_a?(::Hash) ? pop : {}
41
+ end
42
+ end
43
+
44
+ class Hash
45
+
46
+ # An implementation of select that returns a Hash.
47
+ def _select
48
+ Hash[*self.select do |key, value|
49
+ yield key, value
50
+ end._flatten_once]
51
+ end
52
+ end
53
+
54
+ class Object
55
+
56
+ # Returns the metaclass of self.
57
+ def _metaclass; (class << self; self; end); end
58
+
59
+ # Logger shortcut.
60
+ def _logger_debug s
61
+ s = "** has_many_polymorphs: #{s}"
62
+ RAILS_DEFAULT_LOGGER.debug(s) if RAILS_DEFAULT_LOGGER
63
+ end
64
+
65
+ # Logger shortcut.
66
+ def _logger_warn s
67
+ s = "** has_many_polymorphs: #{s}"
68
+ if RAILS_DEFAULT_LOGGER
69
+ RAILS_DEFAULT_LOGGER.warn(s)
70
+ else
71
+ $stderr.puts(s)
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ class ActiveRecord::Base
78
+
79
+ # Return the base class name as a string.
80
+ def _base_class_name
81
+ self.class.base_class.name.to_s
82
+ end
83
+
84
+ end
@@ -0,0 +1,10 @@
1
+ rover:
2
+ id: 1
3
+ name: Rover
4
+ created_at: "2007-01-01 12:00:00"
5
+ updated_at: "2007-01-04 10:00:00"
6
+ spot:
7
+ id: 2
8
+ name: Spot
9
+ created_at: "2007-01-02 12:00:00"
10
+ updated_at: "2007-01-03 10:00:00"
@@ -0,0 +1,18 @@
1
+ chloe:
2
+ id: 1
3
+ cat_type: Kitten
4
+ name: Chloe
5
+ created_at: "2007-04-01 12:00:00"
6
+ updated_at: "2007-04-04 10:00:00"
7
+ alice:
8
+ id: 2
9
+ cat_type: Kitten
10
+ name: Alice
11
+ created_at: "2007-04-02 12:00:00"
12
+ updated_at: "2007-04-03 10:00:00"
13
+ toby:
14
+ id: 3
15
+ cat_type: Tabby
16
+ name: Toby
17
+ created_at: "2007-04-02 12:00:00"
18
+ updated_at: "2007-04-03 10:00:00"
File without changes
@@ -0,0 +1,12 @@
1
+ swimmy:
2
+ id: 1
3
+ name: Swimmy
4
+ speed: 10
5
+ created_at: "2007-02-01 12:00:00"
6
+ updated_at: "2007-02-04 10:00:00"
7
+ jaws:
8
+ id: 2
9
+ name: Jaws
10
+ speed: 20
11
+ created_at: "2007-02-02 12:00:00"
12
+ updated_at: "2007-02-03 10:00:00"
@@ -0,0 +1,5 @@
1
+ froggy:
2
+ id: 1
3
+ name: Froggy
4
+ created_at: "2007-05-01 12:00:00"
5
+ updated_at: "2007-05-04 10:00:00"
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ bob:
2
+ id: 1
3
+ name: Bob
4
+ age: 45
5
+ created_at: "2007-04-01 12:00:00"
6
+ updated_at: "2007-04-04 10:00:00"
7
+
@@ -0,0 +1,11 @@
1
+ kibbles:
2
+ the_petfood_primary_key: 1
3
+ name: Kibbles
4
+ created_at: "2007-06-01 12:00:00"
5
+ updated_at: "2007-06-04 10:00:00"
6
+ bits:
7
+ the_petfood_primary_key: 2
8
+ name: Bits
9
+ created_at: "2007-06-02 12:00:00"
10
+ updated_at: "2007-06-03 10:00:00"
11
+
@@ -0,0 +1,5 @@
1
+ shamu:
2
+ id: 1
3
+ name: Shamu
4
+ created_at: "2007-03-01 12:00:00"
5
+ updated_at: "2007-03-04 10:00:00"
@@ -0,0 +1,10 @@
1
+ puma:
2
+ id: 1
3
+ name: Puma
4
+ created_at: "2007-07-01 12:00:00"
5
+ updated_at: "2007-07-04 10:00:00"
6
+ jacrazy:
7
+ id: 2
8
+ name: Jacrazy
9
+ created_at: "2007-07-02 12:00:00"
10
+ updated_at: "2007-07-03 10:00:00"
@@ -0,0 +1,42 @@
1
+ require 'fileutils'
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+
4
+ class TaggingGeneratorTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ Dir.chdir RAILS_ROOT do
8
+ truncate
9
+
10
+ # Revert environment lib requires
11
+ FileUtils.cp "config/environment.rb.canonical", "config/environment.rb"
12
+
13
+ # Delete generator output
14
+ ["app/models/tag.rb", "app/models/tagging.rb",
15
+ "test/unit/tag_test.rb", "test/unit/tagging_test.rb",
16
+ "test/fixtures/tags.yml", "test/fixtures/taggings.yml",
17
+ "lib/tagging_extensions.rb",
18
+ "db/migrate/010_create_tags_and_taggings.rb"].each do |file|
19
+ File.delete file if File.exist? file
20
+ end
21
+
22
+ # Rebuild database
23
+ Echoe.silence do
24
+ system("ruby #{HERE}/setup.rb")
25
+ end
26
+ end
27
+ end
28
+
29
+ alias :teardown :setup
30
+
31
+ def test_generator
32
+ Dir.chdir RAILS_ROOT do
33
+ Echoe.silence do
34
+ assert system("script/generate tagging Stick Stone -q -f")
35
+ assert system("rake db:migrate")
36
+ assert system("rake db:fixtures:load")
37
+ assert system("rake test:units")
38
+ end
39
+ end
40
+ end
41
+
42
+ end