Skip to content

Commit

Permalink
Merge pull request #99 from rueckerl/master
Browse files Browse the repository at this point in the history
Replaced ActsAsTaggableOnSteroids with ActsAsTaggableOn.
  • Loading branch information
gaelian committed Jan 9, 2016
2 parents 3c17dcd + 196d564 commit 5e97796
Show file tree
Hide file tree
Showing 52 changed files with 120 additions and 1,778 deletions.
12 changes: 4 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem 'rails', '~> 4.2.4'
gem 'sass-rails'

platforms :ruby do
# gem 'pg'
gem 'sqlite3'
end

Expand All @@ -35,7 +36,7 @@ gem 'jquery-rails'
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'chronic'
gem 'coderay', '~> 1.0.5'
gem 'lesstile', '~> 1.1.0'
gem 'formtastic'
Expand All @@ -44,6 +45,7 @@ gem 'exception_notification', '~> 2.5.2'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'omniauth-openid'
gem 'acts-as-taggable-on', '~> 3.5'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
Expand All @@ -54,13 +56,7 @@ group :test do
gem 'cucumber-websteps', :require => false
gem 'factory_girl'
gem 'rspec'

# Temporary fix for current compatibility issue with Rails 4.2.x and rspec-activemodel-mocks. Should be able to go
# back to the standard rspec-activemodel-mocks gem once this issue is resolved:
# https://github.com/rspec/rspec-activemodel-mocks/pull/10
gem 'rspec-activemodel-mocks', :git => 'https://github.com/jdelStrother/rspec-activemodel-mocks.git',
:branch => 'read_attribute'

gem 'rspec-activemodel-mocks'
gem 'rspec-collection_matchers'
gem 'nokogiri', '~> 1.6.0'
gem 'webrat'
Expand Down
14 changes: 11 additions & 3 deletions app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ def category_links_for_navigation

def get_tags_for_published_posts
published_posts = Post.where.not(:published_at => nil)
published_tag_names = published_posts.collect { |post| post.cached_tag_list.split(',') }.flatten.uniq
published_tag_names.each { |tag| tag.strip! }
Tag.where(:name => published_tag_names).sort_by { |tag| tag.taggings.size }.reverse
published_tag_names = published_posts.collect{ |post|
unless post.cached_tag_list.nil?
post.cached_tag_list.split(',')
end
}.flatten.uniq
published_tag_names.each do |tag|
unless tag.nil?
tag.strip!
end
end
ActsAsTaggableOn::Tag.where(:name => published_tag_names).sort_by { |tag| tag.taggings.size }.reverse
end
end
19 changes: 9 additions & 10 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def build_for_preview(params)
post.generate_slug
post.set_dates
post.apply_filter
TagList.from(params[:tag_list]).each do |tag|
post.tags << Tag.new(:name => tag)
post.tag_list.each do |tag|
post.tags << ActsAsTaggableOn::Tag.find_or_create_with_like_by_name(tag)
end
post
end
Expand All @@ -57,14 +57,11 @@ def find_recent(options = {})
conditions = ['published_at < ?', Time.zone.now]
limit = options[:limit] ||= DEFAULT_LIMIT

options = {
:order => order,
:conditions => conditions,
:limit => limit
}.merge(options)

if tag
find_tagged_with(tag, options)
result = Post.tagged_with(tag)
result = result.where(conditions)
result = result.includes(:tags) if include_tags
result.order(order).limit(limit)
else
result = where(conditions)
result = result.includes(:tags) if include_tags
Expand Down Expand Up @@ -138,7 +135,9 @@ def generate_slug

def tag_list=(value)
value = value.split(',') if value.is_a?(String)
value.map!{ |tag_name| Tag::filter_name(tag_name) }
value.map!{ |tag_name| tag_name.gsub!('&', 'and')
tag_name.gsub!(/[^A-Za-z0-9_ \.-]/, '')
tag_name }

# TODO: Contribute this back to acts_as_taggable_on_steroids plugin
value = value.join(", ") if value.respond_to?(:join)
Expand Down
2 changes: 1 addition & 1 deletion app/models/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def comment_count
end

def tag_count
Tag.count
ActsAsTaggableOn::Tag.count
end
end
43 changes: 0 additions & 43 deletions app/models/tag.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/models/tagging.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/admin/posts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= form.inputs do -%>
<%= form.input :title -%>
<%= form.input :body, :hint => "<a href='http://redcloth.org/textile'>Textile enabled</a>. Use Ctrl+E to switch between preview and edit mode.".html_safe -%>
<%= form.input :tag_list, :as => 'string', :required => false, :hint => 'Comma separated: ruby, rails&hellip;'.html_safe -%>
<%= form.input :tag_list, :input_html => { :value => @post.tag_list.join(', ')}, :as => 'string', :required => false, :hint => 'Comma separated: ruby, rails&hellip;'.html_safe -%>
<% end -%>
<%= form.inputs do -%>
<%= form.input :published_at_natural, :label => 'Published at', :as => 'string', :hint => 'Examples: now, yesterday, 1 hour from now, '.html_safe + link_to("etc".html_safe, "http://chronic.rubyforge.org/") + '. Leave blank for an unpublished draft.' -%>
Expand Down
11 changes: 0 additions & 11 deletions config/initializers/acts_as_taggable_on_steroids.rb

This file was deleted.

56 changes: 56 additions & 0 deletions db/migrate/20151220095617_update_tagging_tables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class UpdateTaggingTables < ActiveRecord::Migration
def up
#update tables
change_column_null :tags, :taggings_count, true

change_table :taggings do |t|
#t.references :tag

# You should make sure that the column created is
# long enough to store the required class names.
# t.references :taggable, polymorphic: true
t.references :tagger, polymorphic: true
t.string :taggable_type, null: false, default: 'Post'

# Limit is created to prevent MySQL error on index
# length for MyISAM table type: http://bit.ly/vgW2Ql
t.string :context, limit: 128, default: 'tags', null: false

#t.datetime :created_at
end
# set default before to force the db filling this field
change_column_default(:taggings, :taggable_type, nil)
change_column_default(:taggings, :context, nil)

if ActsAsTaggableOn::Utils.using_mysql?
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
end

#drop old index structures
ActiveRecord::Base.connection.indexes(:taggings).each do |index|
remove_index :taggings, :name => index.name
end
ActiveRecord::Base.connection.indexes(:tags).each do |index|
remove_index :tags, :name => index.name
end

#create new index structures

add_index :tags, :name, unique: true
add_index :taggings,
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
unique: true, name: 'taggings_idx'
add_index :taggings, [:taggable_id, :taggable_type, :context]

#update data
#TODO: test what this really does
ActsAsTaggableOn::Tag.reset_column_information
ActsAsTaggableOn::Tag.find_each do |tag|
ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
30 changes: 17 additions & 13 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150414113518) do
ActiveRecord::Schema.define(version: 20151220095617) do

create_table "comments", force: true do |t|
create_table "comments", force: :cascade do |t|
t.integer "post_id", null: false
t.string "author", null: false
t.string "author_url", null: false
Expand All @@ -27,7 +27,7 @@
add_index "comments", ["created_at"], name: "index_comments_on_created_at"
add_index "comments", ["post_id"], name: "index_comments_on_post_id"

create_table "omni_auth_details", force: true do |t|
create_table "omni_auth_details", force: :cascade do |t|
t.string "provider", null: false
t.string "uid"
t.text "info"
Expand All @@ -37,7 +37,7 @@
t.datetime "updated_at"
end

create_table "pages", force: true do |t|
create_table "pages", force: :cascade do |t|
t.string "title", null: false
t.string "slug", null: false
t.text "body", null: false
Expand All @@ -50,7 +50,7 @@
add_index "pages", ["slug"], name: "pages_slug_unique_idx"
add_index "pages", ["title"], name: "index_pages_on_title"

create_table "posts", force: true do |t|
create_table "posts", force: :cascade do |t|
t.string "title", null: false
t.string "slug", null: false
t.text "body", null: false
Expand All @@ -67,7 +67,7 @@
add_index "posts", ["published_at"], name: "index_posts_on_published_at"
add_index "posts", ["slug"], name: "posts_slug_unique_idx"

create_table "sessions", force: true do |t|
create_table "sessions", force: :cascade do |t|
t.string "session_id", null: false
t.text "data"
t.datetime "created_at"
Expand All @@ -77,23 +77,27 @@
add_index "sessions", ["session_id"], name: "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at"

create_table "taggings", force: true do |t|
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.datetime "created_at"
t.integer "tagger_id"
t.string "tagger_type"
t.string "taggable_type", null: false
t.string "context", limit: 128
end

add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id"
add_index "taggings", ["taggable_id"], name: "index_taggings_on_taggable_id_and_taggable_type"
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"

create_table "tags", force: true do |t|
create_table "tags", force: :cascade do |t|
t.string "name"
t.integer "taggings_count", default: 0, null: false
t.integer "taggings_count", default: 0
end

add_index "tags", ["name"], name: "index_tags_on_name"
add_index "tags", ["name"], name: "index_tags_on_name", unique: true

create_table "undo_items", force: true do |t|
create_table "undo_items", force: :cascade do |t|
t.string "type", null: false
t.datetime "created_at", null: false
t.text "data"
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/factories.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'factory_girl'

FactoryGirl.define do
factory :tag do
factory :tag, :class => ActsAsTaggableOn::Tag do
name 'Tag'
end

Expand Down
Loading

0 comments on commit 5e97796

Please sign in to comment.