Permalink
Browse files

cleanup from rails 2

  • Loading branch information...
1 parent 5f6d96c commit b223901890e3a057ade497a5f577dca7397e7c45 @artemk artemk committed Dec 18, 2011
@@ -53,11 +53,7 @@ def tag_counts_on(context, options = {})
def all_tag_counts(options = {})
options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit, :on, :id
- scope = if ActiveRecord::VERSION::MAJOR >= 3
- {}
- else
- scope(:find) || {}
- end
+ scope = {}
## Generate conditions:
options[:conditions] = sanitize_sql(options[:conditions]) if options[:conditions]
@@ -92,8 +88,6 @@ def all_tag_counts(options = {})
tag_joins = [
].compact
- [tagging_joins, tag_joins].each(&:reverse!) if ActiveRecord::VERSION::MAJOR < 3
-
## Generate scope:
tagging_scope = ActsAsTaggableOn::Tagging.select("#{ActsAsTaggableOn::Tagging.table_name}.tag_id, COUNT(#{ActsAsTaggableOn::Tagging.table_name}.tag_id) AS tags_count")
tag_scope = ActsAsTaggableOn::Tag.select("#{ActsAsTaggableOn::Tag.table_name}.*, #{ActsAsTaggableOn::Tagging.table_name}.tags_count AS count").order(options[:order]).limit(options[:limit])
@@ -112,18 +106,12 @@ def all_tag_counts(options = {})
group_columns = "#{ActsAsTaggableOn::Tagging.table_name}.tag_id"
- if ActiveRecord::VERSION::MAJOR >= 3
- # Append the current scope to the scope, because we can't use scope(:find) in RoR 3.0 anymore:
- scoped_select = "#{table_name}.#{primary_key}"
- tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{select(scoped_select).to_sql})").
- group(group_columns).
- having(having)
- else
- # Having is not available in 2.3.x:
- group_by = "#{group_columns} HAVING COUNT(*) > 0"
- group_by << " AND #{having}" unless having.blank?
- tagging_scope = tagging_scope.group(group_by)
- end
+ # Append the current scope to the scope, because we can't use scope(:find) in RoR 3.0 anymore:
+ scoped_select = "#{table_name}.#{primary_key}"
+ tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{select(scoped_select).to_sql})").
+ group(group_columns).
+ having(having)
+
tag_scope = tag_scope.joins("JOIN (#{tagging_scope.to_sql}) AS #{ActsAsTaggableOn::Tagging.table_name} ON #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.id")
tag_scope
@@ -74,20 +74,12 @@
it "should require a name" do
@tag.valid?
- if ActiveRecord::VERSION::MAJOR >= 3
- @tag.errors[:name].should == ["can't be blank"]
- else
- @tag.errors[:name].should == "can't be blank"
- end
+ @tag.errors[:name].should == ["can't be blank"]
@tag.name = "something"
@tag.valid?
- if ActiveRecord::VERSION::MAJOR >= 3
- @tag.errors[:name].should == []
- else
- @tag.errors[:name].should be_nil
- end
+ @tag.errors[:name].should == []
end
it "should equal a tag with the same name" do
@@ -142,20 +142,9 @@
TaggableModel.tagged_with(['rails, css'], :on => :needs, :any => true).tagged_with(['c++', 'java'], :on => :offerings, :any => true).to_a.should == [bob]
end
- if ActiveRecord::VERSION::MAJOR >= 3
- it "should not return read-only records" do
- TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
- TaggableModel.tagged_with("ruby").first.should_not be_readonly
- end
- else
- xit "should not return read-only records" do
- # apparantly, there is no way to set readonly to false in a scope if joins are made
- end
-
- it "should be possible to return writable records" do
- TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
- TaggableModel.tagged_with("ruby").first(:readonly => false).should_not be_readonly
- end
+ it "should not return read-only records" do
+ TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
+ TaggableModel.tagged_with("ruby").first.should_not be_readonly
end
it "should be able to get scoped tag counts" do

0 comments on commit b223901

Please sign in to comment.