Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes for acts_as_ordered_taggable #243

Merged
merged 1 commit into from

2 participants

@chrismhilton
  1. ensure that tag associations & methods are created via core module when a model includes multiple calls to acts_as_ordered_taggable
  2. better tests
@chrismhilton chrismhilton Fixes for acts_as_ordered_taggable
1. ensure that tag associations & methods are created via core module
when a model includes multiple calls to acts_as_ordered_taggable
2. better tests
a12f83a
@artemk artemk merged commit dc2798d into from
@chrismhilton

@artemk all the tests pass in my development environment. In an attempt to re-create the failure I have reinstalled mysql so I am now running v5.5.20; installed ruby-1.8.7-p358 to run the tests using this ruby; and cloned this repo to run the tests. After each of those steps the mysql tests still pass. Could you tell me what version of mysql you are using for the build?

@artemk
Collaborator

i'm not sure which mysql version travis-ci team uses. But this failes on all ruby versions.

@chrismhilton

Okay third time lucky via a new pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. @chrismhilton

    Fixes for acts_as_ordered_taggable

    chrismhilton authored
    1. ensure that tag associations & methods are created via core module
    when a model includes multiple calls to acts_as_ordered_taggable
    2. better tests
This page is out of date. Refresh to see the latest.
View
6 lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
@@ -52,11 +52,11 @@ def all_#{tags_type}_list
end
end
- def acts_as_taggable_on(*args)
- super(*args)
+ def taggable_on(preserve_tag_order, *tag_types)
+ super(preserve_tag_order, *tag_types)
initialize_acts_as_taggable_on_core
end
-
+
# all column names are necessary for PostgreSQL group clause
def grouped_column_names_for(object)
object.column_names.map { |column| "#{object.table_name}.#{column}" }.join(", ")
View
3  lib/acts_as_taggable_on/taggable.rb
@@ -64,6 +64,9 @@ def acts_as_ordered_taggable_on(*tag_types)
# as it's not possible to add another arguement to the method
# without the tag_types being enclosed in square brackets
#
+ # NB: method overridden in core module in order to create tag type
+ # associations and methods after this logic has executed
+ #
def taggable_on(preserve_tag_order, *tag_types)
tag_types = tag_types.to_a.flatten.compact.map(&:to_sym)
View
1  spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
@@ -13,6 +13,7 @@
before(:each) do
clean_database!
TaggableModel.tag_types = []
+ TaggableModel.preserve_tag_order = false
TaggableModel.acts_as_ordered_taggable_on(:ordered_tags)
@taggable = TaggableModel.new(:name => "Bob Jones")
end
View
37 spec/acts_as_taggable_on/taggable_spec.rb
@@ -3,10 +3,37 @@
describe "Taggable To Preserve Order" do
before(:each) do
clean_database!
- TaggableModel.tag_types = []
- TaggableModel.acts_as_ordered_taggable_on(:tags)
- @taggable = TaggableModel.new(:name => "Bob Jones")
- @taggables = [@taggable, TaggableModel.new(:name => "John Doe")]
+ @taggable = OrderedTaggableModel.new(:name => "Bob Jones")
+ end
+
+ it "should have tag types" do
+ [:tags, :colours].each do |type|
+ OrderedTaggableModel.tag_types.should include type
+ end
+
+ @taggable.tag_types.should == OrderedTaggableModel.tag_types
+ end
+
+ it "should have tag associations" do
+ [:tags, :colours].each do |type|
+ @taggable.respond_to?(type).should be_true
+ @taggable.respond_to?("#{type.to_s.singularize}_taggings").should be_true
+ end
+ end
+
+ it "should have tag associations ordered by created_at" do
+ [:tags, :colours].each do |type|
+ OrderedTaggableModel.reflect_on_association(type).options[:order].should include('created_at')
+ OrderedTaggableModel.reflect_on_association("#{type.to_s.singularize}_taggings".to_sym).options[:order].should include('created_at')
+ end
+ end
+
+ it "should have tag methods" do
+ [:tags, :colours].each do |type|
+ @taggable.respond_to?("#{type.to_s.singularize}_list").should be_true
+ @taggable.respond_to?("#{type.to_s.singularize}_list=").should be_true
+ @taggable.respond_to?("all_#{type.to_s}_list").should be_true
+ end
end
it "should return tag list in the order the tags were created" do
@@ -67,8 +94,6 @@
describe "Taggable" do
before(:each) do
clean_database!
- TaggableModel.tag_types = []
- TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
@taggable = TaggableModel.new(:name => "Bob Jones")
@taggables = [@taggable, TaggableModel.new(:name => "John Doe")]
end
View
5 spec/models.rb
@@ -42,3 +42,8 @@ class NonStandardIdTaggableModel < ActiveRecord::Base
acts_as_taggable_on :needs, :offerings
has_many :untaggable_models
end
+
+class OrderedTaggableModel < ActiveRecord::Base
+ acts_as_ordered_taggable
+ acts_as_ordered_taggable_on :colours
+end
View
5 spec/schema.rb
@@ -53,4 +53,9 @@
t.column :name, :string
t.column :type, :string
end
+
+ create_table :ordered_taggable_models, :force => true do |t|
+ t.column :name, :string
+ t.column :type, :string
+ end
end
View
4 spec/spec_helper.rb
@@ -31,6 +31,8 @@ def freq
end
end
+# set adapter to use, default is sqlite3
+# to use an alternative adapter run => rake spec DB='postgresql'
db_name = ENV['DB'] || 'sqlite3'
database_yml = File.expand_path('../database.yml', __FILE__)
@@ -72,7 +74,7 @@ def freq
def clean_database!
models = [ActsAsTaggableOn::Tag, ActsAsTaggableOn::Tagging, TaggableModel, OtherTaggableModel, InheritingTaggableModel,
- AlteredInheritingTaggableModel, TaggableUser, UntaggableModel]
+ AlteredInheritingTaggableModel, TaggableUser, UntaggableModel, OrderedTaggableModel]
models.each do |model|
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
end
Something went wrong with that request. Please try again.