Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with ActiveRecord only instead of full Rails stack #523

Merged
merged 5 commits into from
May 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ env:
- DB=mysql
- DB=postgresql
gemfile:
- gemfiles/rails_3.2.gemfile
- gemfiles/rails_4.0.gemfile
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_edge.gemfile
- gemfiles/activerecord_3.2.gemfile
- gemfiles/activerecord_4.0.gemfile
- gemfiles/activerecord_4.1.gemfile
- gemfiles/activerecord_edge.gemfile
cache: bundler
script: bundle exec rake
before_install: gem install bundler
bundler_args: '--without local_development'
matrix:
fast_finish: true
allow_failures:
- gemfile: gemfiles/rails_edge.gemfile
- rvm: rbx-2
- gemfile: gemfiles/activerecord_edge.gemfile
- rvm: rbx-2
21 changes: 13 additions & 8 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
appraise "rails-3.2" do
gem "rails", "~> 3.2"
appraise "activerecord-3.2" do
gem "activerecord", "~> 3.2"
gem "actionpack", "~> 3.2"
end

appraise "rails-4.0" do
gem "rails", "~> 4.0"
appraise "activerecord-4.0" do
gem "activerecord", "~> 4.0"
gem "actionpack", "~> 4.0"
end

appraise "rails-4.1" do
gem "rails", "~> 4.1.0"
appraise "activerecord-4.1" do
gem "activerecord", "~> 4.1"
gem "actionpack", "~> 4.1"
end

appraise "rails-edge" do
gem "rails", github: "rails/rails"
appraise "activerecord-edge" do
gem "activerecord", github: "rails/rails"
gem "actionpack", github: "rails/rails"
gem 'arel', github: 'rails/arel'
end
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ Re-run the migrations generator
rake acts_as_taggable_on_engine:install:migrations

It will create any new migrations and skip existing ones


##Breaking changes:

- ActsAsTaggableOn::Tag is not extend with ActsAsTaggableOn::Utils anymore.
Please use ActsAsTaggableOn::Utils instead
2 changes: 1 addition & 1 deletion acts-as-taggable-on.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Gem::Specification.new do |gem|
end

gem.add_runtime_dependency 'activerecord', ['>= 3', '< 5']
gem.add_runtime_dependency 'activesupport', ['>= 3', '< 5']
gem.add_runtime_dependency 'actionpack', ['>= 3', '< 5']

gem.add_development_dependency 'sqlite3'
Expand All @@ -35,4 +34,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'ammeter'
gem.add_development_dependency 'barrier'
gem.add_development_dependency 'database_cleaner'
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

source "https://rubygems.org"

gem "rails", "~> 3.2"
gem "activerecord", "~> 3.2"
gem "actionpack", "~> 3.2"

group :local_development do
gem "guard"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

source "https://rubygems.org"

gem "rails", "~> 4.0"
gem "activerecord", "~> 4.0"
gem "actionpack", "~> 4.0"

group :local_development do
gem "guard"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

source "https://rubygems.org"

gem "rails", "~> 4.1.0"
gem "activerecord", "~> 4.1"
gem "actionpack", "~> 4.1"

group :local_development do
gem "guard"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

source "https://rubygems.org"

gem "rails", :github => "rails/rails"
gem "activerecord", :github => "rails/rails"
gem "actionpack", :github => "rails/rails"
gem "arel", :github => "rails/arel"

group :local_development do
gem "guard"
Expand Down
4 changes: 2 additions & 2 deletions lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def safe_to_sql(relation)

def generate_tagging_scope_in_clause(tagging_scope, table_name, primary_key)
table_name_pkey = "#{table_name}.#{primary_key}"
if ActsAsTaggableOn::Tag.using_mysql?
if ActsAsTaggableOn::Utils.using_mysql?
# See https://github.com/mbleigh/acts-as-taggable-on/pull/457 for details
scoped_ids = select(table_name_pkey).map(&:id)
tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)", scoped_ids)
else
tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{safe_to_sql(select(table_name_pkey))})")
end

return tagging_scope
tagging_scope
end

def tagging_conditions(options)
Expand Down
31 changes: 15 additions & 16 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ def initialize_acts_as_taggable_on_core
# when preserving tag order, include order option so that for a 'tags' context
# the associations tag_taggings & tags are always returned in created order
has_many_with_taggable_compatibility context_taggings, as: :taggable,
dependent: :destroy,
class_name: 'ActsAsTaggableOn::Tagging',
order: taggings_order,
conditions: ["#{ActsAsTaggableOn::Tagging.table_name}.context = (?)", tags_type],
include: :tag
dependent: :destroy,
class_name: 'ActsAsTaggableOn::Tagging',
order: taggings_order,
conditions: ["#{ActsAsTaggableOn::Tagging.table_name}.context = (?)", tags_type],
include: :tag

has_many_with_taggable_compatibility context_tags, through: context_taggings,
source: :tag,
class_name: 'ActsAsTaggableOn::Tag',
order: taggings_order
source: :tag,
class_name: 'ActsAsTaggableOn::Tag',
order: taggings_order

end

Expand Down Expand Up @@ -96,13 +96,13 @@ def tagged_with(tags, options = {})
context = options.delete(:on)
owned_by = options.delete(:owned_by)
alias_base_name = undecorated_table_name.gsub('.', '_')
quote = ActsAsTaggableOn::Tag.using_postgresql? ? '"' : ''
quote = ActsAsTaggableOn::Utils.using_postgresql? ? '"' : ''

if options.delete(:exclude)
if options.delete(:wild)
tags_conditions = tag_list.map { |t| sanitize_sql(["#{ActsAsTaggableOn::Tag.table_name}.name #{like_operator} ? ESCAPE '!'", "%#{escape_like(t)}%"]) }.join(' OR ')
tags_conditions = tag_list.map { |t| sanitize_sql(["#{ActsAsTaggableOn::Tag.table_name}.name #{ActsAsTaggableOn::Utils.like_operator} ? ESCAPE '!'", "%#{ActsAsTaggableOn::Utils.escape_like(t)}%"]) }.join(' OR ')
else
tags_conditions = tag_list.map { |t| sanitize_sql(["#{ActsAsTaggableOn::Tag.table_name}.name #{like_operator} ?", t]) }.join(' OR ')
tags_conditions = tag_list.map { |t| sanitize_sql(["#{ActsAsTaggableOn::Tag.table_name}.name #{ActsAsTaggableOn::Utils.like_operator} ?", t]) }.join(' OR ')
end

conditions << "#{table_name}.#{primary_key} NOT IN (SELECT #{ActsAsTaggableOn::Tagging.table_name}.taggable_id FROM #{ActsAsTaggableOn::Tagging.table_name} JOIN #{ActsAsTaggableOn::Tag.table_name} ON #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND (#{tags_conditions}) WHERE #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = #{quote_value(base_class.name, nil)})"
Expand Down Expand Up @@ -183,7 +183,7 @@ def tagged_with(tags, options = {})
group ||= [] # Rails interprets this as a no-op in the group() call below
if options.delete(:order_by_matching_tag_count)
select_clause = "#{table_name}.*, COUNT(#{taggings_alias}.tag_id) AS #{taggings_alias}_count"
group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
group_columns = ActsAsTaggableOn::Utils.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
group = group_columns
order_by << "#{taggings_alias}_count DESC"

Expand All @@ -195,7 +195,7 @@ def tagged_with(tags, options = {})

joins << ' AND ' + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context

group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
group_columns = ActsAsTaggableOn::Utils.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
group = group_columns
having = "COUNT(#{taggings_alias}.taggable_id) = #{tags.size}"
end
Expand Down Expand Up @@ -284,7 +284,7 @@ def all_tags_on(context)
opts = ["#{tagging_table_name}.context = ?", context.to_s]
scope = base_tags.where(opts)

if ActsAsTaggableOn::Tag.using_postgresql?
if ActsAsTaggableOn::Utils.using_postgresql?
group_columns = grouped_column_names_for(ActsAsTaggableOn::Tag)
scope.order("max(#{tagging_table_name}.created_at)").group(group_columns)
else
Expand Down Expand Up @@ -415,9 +415,8 @@ def save_tags
#
# @param [Array<String>] tag_list Tags to find or create
# @param [Symbol] context The tag context for the tag_list
def find_or_create_tags_from_list_with_context(tag_list, context)
def find_or_create_tags_from_list_with_context(tag_list, _context)
load_tags(tag_list)
end
end
end

2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def exclude_self(klass, id)
end

def group_columns(klass)
if ActsAsTaggableOn::Tag.using_postgresql?
if ActsAsTaggableOn::Utils.using_postgresql?
grouped_column_names_for(klass)
else
"#{klass.table_name}.#{klass.primary_key}"
Expand Down
7 changes: 3 additions & 4 deletions lib/acts_as_taggable_on/tag.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding: utf-8
module ActsAsTaggableOn
class Tag < ::ActiveRecord::Base
extend ActsAsTaggableOn::Utils

attr_accessible :name if defined?(ActiveModel::MassAssignmentSecurity)

Expand Down Expand Up @@ -45,13 +44,13 @@ def self.named_any(list)
end

def self.named_like(name)
clause = ["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(name)}%"]
clause = ["name #{ActsAsTaggableOn::Utils.like_operator} ? ESCAPE '!'", "%#{ActsAsTaggableOn::Utils.escape_like(name)}%"]
where(clause)
end

def self.named_like_any(list)
clause = list.map { |tag|
sanitize_sql(["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(tag.to_s)}%"])
sanitize_sql(["name #{ActsAsTaggableOn::Utils.like_operator} ? ESCAPE '!'", "%#{ActsAsTaggableOn::Utils.escape_like(tag.to_s)}%"])
}.join(' OR ')
where(clause)
end
Expand Down Expand Up @@ -113,7 +112,7 @@ def comparable_name(str)
end

def binary
using_mysql? ? 'BINARY ' : nil
ActsAsTaggableOn::Utils.using_mysql? ? 'BINARY ' : nil
end

def unicode_downcase(string)
Expand Down
4 changes: 2 additions & 2 deletions lib/acts_as_taggable_on/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def acts_as_ordered_taggable_on(*tag_types)
# Make a model taggable on specified contexts
# and optionally preserves the order in which tags are created
#
# Seperate methods used above for backwards compatibility
# Separate methods used above for backwards compatibility
# so that the original acts_as_taggable_on method is unaffected
# as it's not possible to add another arguement to the method
# as it's not possible to add another argument to the method
# without the tag_types being enclosed in square brackets
#
# NB: method overridden in core module in order to create tag type
Expand Down
40 changes: 26 additions & 14 deletions lib/acts_as_taggable_on/tagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@ module ClassMethods
def acts_as_tagger(opts={})
class_eval do
has_many_with_taggable_compatibility :owned_taggings,
opts.merge(
as: :tagger,
dependent: :destroy,
class_name: 'ActsAsTaggableOn::Tagging'
)
opts.merge(
as: :tagger,
dependent: :destroy,
class_name: 'ActsAsTaggableOn::Tagging'
)

has_many_with_taggable_compatibility :owned_tags,
through: :owned_taggings,
source: :tag,
class_name: 'ActsAsTaggableOn::Tag',
uniq: true
through: :owned_taggings,
source: :tag,
class_name: 'ActsAsTaggableOn::Tag',
uniq: true
end

include ActsAsTaggableOn::Tagger::InstanceMethods
extend ActsAsTaggableOn::Tagger::SingletonMethods
end

def is_tagger?
def tagger?
false
end

def is_tagger?
tagger?
end
end

module InstanceMethods
Expand All @@ -54,23 +58,31 @@ def tag(taggable, opts={})
skip_save = opts.delete(:skip_save)
return false unless taggable.respond_to?(:is_taggable?) && taggable.is_taggable?

fail 'You need to specify a tag context using :on' unless opts.key?(:on)
fail 'You need to specify some tags using :with' unless opts.key?(:with)
fail 'You need to specify a tag context using :on' unless opts.key?(:on)
fail 'You need to specify some tags using :with' unless opts.key?(:with)
fail "No context :#{opts[:on]} defined in #{taggable.class}" unless opts[:force] || taggable.tag_types.include?(opts[:on])

taggable.set_owner_tag_list_on(self, opts[:on].to_s, opts[:with])
taggable.save unless skip_save
end

def is_tagger?
def tagger?
self.class.is_tagger?
end

def is_tagger?
tagger?
end
end

module SingletonMethods
def is_tagger?
def tagger?
true
end

def is_tagger?
tagger?
end
end
end
end
Loading