Use Ruby 1.9+ hash syntax

This commit is contained in:
Jon Atack 2015-11-18 23:51:23 +01:00
parent eab5d391b4
commit b8e5fbc52e
1 changed files with 22 additions and 22 deletions

View File

@ -30,8 +30,8 @@ class Person < ActiveRecord::Base
else
default_scope { order(id: :desc) }
end
belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
has_many :children, :class_name => 'Person', :foreign_key => :parent_id
belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
has_many :children, class_name: 'Person', foreign_key: :parent_id
has_many :articles
if ActiveRecord::VERSION::MAJOR == 3
has_many :published_articles, conditions: { published: true }, class_name: "Article"
@ -39,9 +39,9 @@ class Person < ActiveRecord::Base
has_many :published_articles, ->{ where(published: true) }, class_name: "Article"
end
has_many :comments
has_many :authored_article_comments, :through => :articles,
:source => :comments, :foreign_key => :person_id
has_many :notes, :as => :notable
has_many :authored_article_comments, through: :articles,
source: :comments, foreign_key: :person_id
has_many :notes, as: :notable
scope :restricted, lambda { where("restricted = 1") }
scope :active, lambda { where("active = 1") }
@ -52,7 +52,7 @@ class Person < ActiveRecord::Base
alias_attribute :full_name, :name
ransacker :reversed_name, :formatter => proc { |v| v.reverse } do |parent|
ransacker :reversed_name, formatter: proc { |v| v.reverse } do |parent|
parent.table[:name]
end
@ -110,7 +110,7 @@ class Article < ActiveRecord::Base
belongs_to :person
has_many :comments
has_and_belongs_to_many :tags
has_many :notes, :as => :notable
has_many :notes, as: :notable
if ActiveRecord::VERSION::STRING >= '3.1'
default_scope { where("'default_scope' = 'default_scope'") }
@ -147,7 +147,7 @@ class Tag < ActiveRecord::Base
end
class Note < ActiveRecord::Base
belongs_to :notable, :polymorphic => true
belongs_to :notable, polymorphic: true
end
module Schema
@ -155,7 +155,7 @@ module Schema
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table :people, :force => true do |t|
create_table :people, force: true do |t|
t.integer :parent_id
t.string :name
t.string :email
@ -172,7 +172,7 @@ module Schema
t.timestamps null: false
end
create_table :articles, :force => true do |t|
create_table :articles, force: true do |t|
t.integer :person_id
t.string :title
t.text :subject_header
@ -180,28 +180,28 @@ module Schema
t.boolean :published, default: true
end
create_table :comments, :force => true do |t|
create_table :comments, force: true do |t|
t.integer :article_id
t.integer :person_id
t.text :body
end
create_table :tags, :force => true do |t|
create_table :tags, force: true do |t|
t.string :name
end
create_table :articles_tags, :force => true, :id => false do |t|
create_table :articles_tags, force: true, id: false do |t|
t.integer :article_id
t.integer :tag_id
end
create_table :notes, :force => true do |t|
create_table :notes, force: true do |t|
t.integer :notable_id
t.string :notable_type
t.string :note
end
create_table :recommendations, :force => true do |t|
create_table :recommendations, force: true do |t|
t.integer :person_id
t.integer :target_person_id
t.integer :article_id
@ -210,22 +210,22 @@ module Schema
10.times do
person = Person.make
Note.make(:notable => person)
Note.make(notable: person)
3.times do
article = Article.make(:person => person)
article = Article.make(person: person)
3.times do
article.tags = [Tag.make, Tag.make, Tag.make]
end
Note.make(:notable => article)
Note.make(notable: article)
10.times do
Comment.make(:article => article, :person => person)
Comment.make(article: article, person: person)
end
end
end
Comment.make(
:body => 'First post!',
:article => Article.make(:title => 'Hello, world!')
)
body: 'First post!',
article: Article.make(title: 'Hello, world!')
)
end
end