Skip to content

Commit

Permalink
Consistent string quoting.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Oct 28, 2017
1 parent de6aa35 commit 49b7b4f
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 167 deletions.
30 changes: 15 additions & 15 deletions Appraisals
@@ -1,26 +1,26 @@
appraise 'rails_3_2' do
gem 'rails', '~> 3.2.22.5'
gem 'mysql2', '~> 0.3.10', :platform => :ruby
appraise "rails_3_2" do
gem "rails", "~> 3.2.22.5"
gem "mysql2", "~> 0.3.10", :platform => :ruby
end if RUBY_VERSION.to_f <= 2.2

appraise 'rails_4_0' do
gem 'rails', '~> 4.0.13'
gem 'mysql2', '~> 0.3.10', :platform => :ruby
appraise "rails_4_0" do
gem "rails", "~> 4.0.13"
gem "mysql2", "~> 0.3.10", :platform => :ruby
end if RUBY_VERSION.to_f < 2.4

appraise 'rails_4_1' do
gem 'rails', '~> 4.1.16'
gem 'mysql2', '~> 0.3.13', :platform => :ruby
appraise "rails_4_1" do
gem "rails", "~> 4.1.16"
gem "mysql2", "~> 0.3.13", :platform => :ruby
end if RUBY_VERSION.to_f < 2.4

appraise 'rails_4_2' do
gem 'rails', '~> 4.2.8'
appraise "rails_4_2" do
gem "rails", "~> 4.2.8"
end if RUBY_VERSION.to_f < 2.4

appraise 'rails_5_0' do
gem 'rails', '~> 5.0.3'
appraise "rails_5_0" do
gem "rails", "~> 5.0.3"
end if RUBY_VERSION.to_f >= 2.2 && RUBY_PLATFORM != "java"

appraise 'rails_5_1' do
gem 'rails', '~> 5.1.1'
appraise "rails_5_1" do
gem "rails", "~> 5.1.1"
end if RUBY_VERSION.to_f >= 2.2 && RUBY_PLATFORM != "java"
18 changes: 9 additions & 9 deletions Gemfile
@@ -1,17 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'test-unit', :platform => :ruby_22
gem "test-unit", :platform => :ruby_22

gem 'mysql2', '~> 0.3', :platform => :ruby
gem 'pg', '~> 0.18', :platform => :ruby
gem 'sqlite3', '~> 1.3', :platform => :ruby
gem "mysql2", "~> 0.3", :platform => :ruby
gem "pg", "~> 0.18", :platform => :ruby
gem "sqlite3", "~> 1.3", :platform => :ruby

gem 'activerecord-jdbcmysql-adapter', '~> 1.3.23', :platform => :jruby
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.23', :platform => :jruby
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.23', :platform => :jruby
gem "activerecord-jdbcmysql-adapter", "~> 1.3.23", :platform => :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.23", :platform => :jruby
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.23", :platform => :jruby

gem 'activerecord', ['>= 3.2.22', '< 5'] if RUBY_PLATFORM == 'java'
gem "activerecord", [">= 3.2.22", "< 5"] if RUBY_PLATFORM == "java"
6 changes: 3 additions & 3 deletions Rakefile
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/setup"
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

Expand Down
6 changes: 3 additions & 3 deletions app/models/gutentag/tag.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true

class Gutentag::Tag < ActiveRecord::Base
self.table_name = 'gutentag_tags'
self.table_name = "gutentag_tags"

has_many :taggings, :class_name => 'Gutentag::Tagging',
has_many :taggings, :class_name => "Gutentag::Tagging",
:dependent => :destroy

attr_accessible :name if ActiveRecord::VERSION::MAJOR == 3

scope :by_weight, ->{ order('gutentag_tags.taggings_count DESC') }
scope :by_weight, ->{ order("gutentag_tags.taggings_count DESC") }

Gutentag.tag_validations.call self

Expand Down
4 changes: 2 additions & 2 deletions app/models/gutentag/tagging.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true

class Gutentag::Tagging < ActiveRecord::Base
self.table_name = 'gutentag_taggings'
self.table_name = "gutentag_taggings"

belongs_to :taggable, :polymorphic => true
belongs_to :tag, :class_name => 'Gutentag::Tag', :counter_cache => true
belongs_to :tag, :class_name => "Gutentag::Tag", :counter_cache => true

validates :taggable, :presence => true
validates :tag, :presence => true
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/1_gutentag_tables.rb
Expand Up @@ -14,7 +14,7 @@ def up
add_index :gutentag_taggings, :tag_id
add_index :gutentag_taggings, [:taggable_type, :taggable_id]
add_index :gutentag_taggings, [:taggable_type, :taggable_id, :tag_id],
:unique => true, :name => 'unique_taggings'
:unique => true, :name => "unique_taggings"

create_table :gutentag_tags do |t|
t.string :name, :null => false
Expand Down
30 changes: 15 additions & 15 deletions gutentag.gemspec
Expand Up @@ -2,24 +2,24 @@

# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = 'gutentag'
s.version = '0.9.0'
s.authors = ['Pat Allan']
s.email = ['pat@freelancing-gods.com']
s.homepage = 'https://github.com/pat/gutentag'
s.summary = 'Good Tags'
s.description = 'A good, simple, solid tagging extension for ActiveRecord'
s.license = 'MIT'
s.name = "gutentag"
s.version = "0.9.0"
s.authors = ["Pat Allan"]
s.email = ["pat@freelancing-gods.com"]
s.homepage = "https://github.com/pat/gutentag"
s.summary = "Good Tags"
s.description = "A good, simple, solid tagging extension for ActiveRecord"
s.license = "MIT"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec}/*`.split("\n")
s.require_paths = ['lib']
s.require_paths = ["lib"]

s.add_runtime_dependency 'activerecord', '>= 3.2.0'
s.add_runtime_dependency "activerecord", ">= 3.2.0"

s.add_development_dependency 'appraisal', '~> 2.1.0'
s.add_development_dependency 'bundler', '>= 1.7.12'
s.add_development_dependency 'combustion', '0.7.0'
s.add_development_dependency 'rails'
s.add_development_dependency 'rspec-rails', '~> 3.1'
s.add_development_dependency "appraisal", "~> 2.1.0"
s.add_development_dependency "bundler", ">= 1.7.12"
s.add_development_dependency "combustion", "0.7.0"
s.add_development_dependency "rails"
s.add_development_dependency "rspec-rails", "~> 3.1"
end
22 changes: 11 additions & 11 deletions lib/gutentag.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'active_record/version'
require "active_record/version"

module Gutentag
def self.dirtier
Expand Down Expand Up @@ -28,12 +28,12 @@ def self.tag_validations=(tag_validations)
end
end

require 'gutentag/active_record'
require 'gutentag/change_state'
require 'gutentag/dirty'
require 'gutentag/persistence'
require 'gutentag/tag_validations'
require 'gutentag/tagged_with'
require "gutentag/active_record"
require "gutentag/change_state"
require "gutentag/dirty"
require "gutentag/persistence"
require "gutentag/tag_validations"
require "gutentag/tagged_with"

if ActiveRecord::VERSION::MAJOR == 3
Gutentag.dirtier = Gutentag::Dirty
Expand All @@ -42,9 +42,9 @@ def self.tag_validations=(tag_validations)
end

if defined?(Rails::Engine)
require 'gutentag/engine'
require "gutentag/engine"
else
require 'active_record'
require_relative '../app/models/gutentag/tag'
require_relative '../app/models/gutentag/tagging'
require "active_record"
require_relative "../app/models/gutentag/tag"
require_relative "../app/models/gutentag/tagging"
end
8 changes: 4 additions & 4 deletions lib/gutentag/active_record.rb
Expand Up @@ -2,9 +2,9 @@

class Gutentag::ActiveRecord
def self.call(model)
model.has_many :taggings, :class_name => 'Gutentag::Tagging',
model.has_many :taggings, :class_name => "Gutentag::Tagging",
:as => :taggable, :dependent => :destroy
model.has_many :tags, :class_name => 'Gutentag::Tag',
model.has_many :tags, :class_name => "Gutentag::Tag",
:through => :taggings

model.after_save :persist_tags
Expand All @@ -14,5 +14,5 @@ def self.call(model)
end
end

require 'gutentag/active_record/class_methods'
require 'gutentag/active_record/instance_methods'
require "gutentag/active_record/class_methods"
require "gutentag/active_record/instance_methods"
6 changes: 3 additions & 3 deletions lib/gutentag/tagged_with.rb
Expand Up @@ -35,6 +35,6 @@ def values
end
end

require 'gutentag/tagged_with/query'
require 'gutentag/tagged_with/id_query'
require 'gutentag/tagged_with/name_query'
require "gutentag/tagged_with/query"
require "gutentag/tagged_with/id_query"
require "gutentag/tagged_with/name_query"
76 changes: 38 additions & 38 deletions spec/acceptance/tag_names_spec.rb
@@ -1,128 +1,128 @@
# frozen_string_literal: true

require 'spec_helper'
require "spec_helper"

describe "Managing tags via names" do
let(:article) { Article.create }

it "returns tag names" do
melbourne = Gutentag::Tag.create :name => 'melbourne'
melbourne = Gutentag::Tag.create :name => "melbourne"

article.tags << melbourne

expect(article.tag_names).to eq(['melbourne'])
expect(article.tag_names).to eq(["melbourne"])
end

it "adds tags via their names" do
article.tag_names << 'melbourne'
article.tag_names << "melbourne"
article.save!

expect(article.tags.collect(&:name)).to eq(['melbourne'])
expect(article.tags.collect(&:name)).to eq(["melbourne"])
end

it "makes model dirty when changing through tag_names" do
article.tag_names << 'melbourne'
article.tag_names << "melbourne"
article.save!

article.tag_names = ['sydney']
article.tag_names = ["sydney"]

expect(article.changed_attributes.stringify_keys).
to eq('tag_names' => ['melbourne'])
to eq("tag_names" => ["melbourne"])
end if Gutentag.dirtier

it "does not make model dirty when changing through tag_names" do
article.tag_names << 'melbourne'
article.tag_names << "melbourne"
article.save!

article.tag_names = ['melbourne']
article.tag_names = ["melbourne"]

expect(article.changed_attributes).to eq({})
end

it "allows for different tag normalisation" do
Gutentag.normaliser = lambda { |name| name.upcase }

tag = Gutentag::Tag.create(:name => 'melbourne')
expect(tag.name).to eq('MELBOURNE')
tag = Gutentag::Tag.create(:name => "melbourne")
expect(tag.name).to eq("MELBOURNE")

Gutentag.normaliser = nil
end

it "doesn't complain when adding an existing tag" do
article.tag_names << 'melbourne'
article.tag_names << 'melbourne'
article.tag_names << "melbourne"
article.tag_names << "melbourne"
article.save!

expect(article.tags.collect(&:name)).to eq(['melbourne'])
expect(article.tags.collect(&:name)).to eq(["melbourne"])
end

it "accepts a completely new set of tags" do
article.tag_names = ['portland', 'oregon']
article.tag_names = ["portland", "oregon"]
article.save!

expect(article.tags.collect(&:name)).to eq(['portland', 'oregon'])
expect(article.tags.collect(&:name)).to eq(["portland", "oregon"])
end

it "does not allow duplication of tags" do
existing = Article.create
existing.tags << Gutentag::Tag.create(:name => 'portland')
existing.tags << Gutentag::Tag.create(:name => "portland")

article.tag_names = ['portland']
article.tag_names = ["portland"]
article.save!

expect(existing.tag_ids).to eq(article.tag_ids)
end

it "appends tag names" do
article.tag_names = ['portland']
article.tag_names += ['oregon', 'ruby']
article.tag_names = ["portland"]
article.tag_names += ["oregon", "ruby"]
article.save!

expect(article.tags.collect(&:name)).to eq(['portland', 'oregon', 'ruby'])
expect(article.tags.collect(&:name)).to eq(["portland", "oregon", "ruby"])
end

it "does not repeat appended names that already exist" do
article.tag_names = ['portland', 'oregon']
article.tag_names += ['oregon', 'ruby']
article.tag_names = ["portland", "oregon"]
article.tag_names += ["oregon", "ruby"]
article.save!

expect(article.tags.collect(&:name)).to eq(['portland', 'oregon', 'ruby'])
expect(article.tags.collect(&:name)).to eq(["portland", "oregon", "ruby"])
end

it "removes a single tag name" do
article.tag_names = ['portland', 'oregon']
article.tag_names.delete 'oregon'
article.tag_names = ["portland", "oregon"]
article.tag_names.delete "oregon"
article.save!

expect(article.tags.collect(&:name)).to eq(['portland'])
expect(article.tags.collect(&:name)).to eq(["portland"])
end

it "removes tag names" do
article.tag_names = ['portland', 'oregon', 'ruby']
article.tag_names -= ['oregon', 'ruby']
article.tag_names = ["portland", "oregon", "ruby"]
article.tag_names -= ["oregon", "ruby"]
article.save!

expect(article.tags.collect(&:name)).to eq(['portland'])
expect(article.tags.collect(&:name)).to eq(["portland"])
end

it "matches tag names ignoring case" do
article.tag_names = ['portland']
article.tag_names += ['Portland']
article.tag_names = ["portland"]
article.tag_names += ["Portland"]
article.save!

expect(article.tags.collect(&:name)).to eq(['portland'])
expect(article.tags.collect(&:name)).to eq(["portland"])

article.tag_names << 'Portland'
article.tag_names << "Portland"
article.save!

expect(article.tags.collect(&:name)).to eq(['portland'])
expect(article.tags.collect(&:name)).to eq(["portland"])
end

it "allows setting of tag names on unpersisted objects" do
article = Article.new :tag_names => ['melbourne', 'pancakes']
article = Article.new :tag_names => ["melbourne", "pancakes"]
article.save!

expect(article.tag_names).to eq(['melbourne', 'pancakes'])
expect(article.tag_names).to eq(["melbourne", "pancakes"])
end

it "allows overriding of tag_names=" do
Expand Down

0 comments on commit 49b7b4f

Please sign in to comment.