Skip to content

Commit 07a247b

Browse files
committed
Minor style changes
Spacing, hash syntax to make Rubocop happy.
1 parent 9665168 commit 07a247b

8 files changed

Lines changed: 33 additions & 56 deletions

File tree

spec/polymorphic_integer_type_spec.rb

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
require 'spec_helper'
22

33
describe PolymorphicIntegerType do
4+
let(:owner) { Person.create(name: "Kyle") }
5+
let(:dog) { Animal.create(name: "Bela", kind: "Dog", owner: owner) }
6+
let(:cat) { Animal.create(name: "Alexi", kind: "Cat") }
47

5-
let(:owner) { Person.create(:name => "Kyle") }
6-
let(:dog) { Animal.create(:name => "Bela", :kind => "Dog", :owner => owner) }
7-
let(:cat) { Animal.create(:name => "Alexi", :kind => "Cat") }
8+
let(:kibble) { Food.create(name: "Kibble") }
9+
let(:chocolate) { Food.create(name: "Choclate") }
810

11+
let(:milk) { Drink.create(name: "milk") }
12+
let(:water) { Drink.create(name: "Water") }
13+
let(:whiskey) { Drink.create(name: "Whiskey") }
914

10-
let(:kibble) { Food.create(:name => "Kibble") }
11-
let(:chocolate) { Food.create(:name => "Choclate") }
12-
13-
14-
let(:milk) { Drink.create(:name => "milk") }
15-
let(:water) { Drink.create(:name => "Water") }
16-
let(:whiskey) { Drink.create(:name => "Whiskey") }
17-
18-
let(:link) { Link.create(:source => source, :target => target) }
15+
let(:link) { Link.create(source: source, target: target) }
1916

2017
context "when the source is nil" do
2118
let(:source) { nil }
@@ -58,13 +55,13 @@
5855

5956
end
6057
context "When a link is given polymorphic record" do
61-
let(:link) { Link.create(:source => source) }
58+
let(:link) { Link.create(source: source) }
6259
let(:source) { cat }
6360
include_examples "proper source"
6461

6562
context "and when it already has a polymorphic record" do
6663
let(:target) { kibble }
67-
before { link.update_attributes(:target => target) }
64+
before { link.update_attributes(target: target) }
6865

6966
include_examples "proper source"
7067
include_examples "proper target"
@@ -74,13 +71,13 @@
7471
end
7572

7673
context "When a link is given polymorphic id and type" do
77-
let(:link) { Link.create(:source_id => source.id, :source_type => source.class.to_s) }
74+
let(:link) { Link.create(source_id: source.id, source_type: source.class.to_s) }
7875
let(:source) { cat }
7976
include_examples "proper source"
8077

8178
context "and when it already has a polymorphic id and type" do
8279
let(:target) { kibble }
83-
before { link.update_attributes(:target_id => target.id, :target_type => target.class.to_s) }
80+
before { link.update_attributes(target_id: target.id, target_type: target.class.to_s) }
8481
include_examples "proper source"
8582
include_examples "proper target"
8683

@@ -90,8 +87,8 @@
9087

9188
context "When using a relation to the links with eagar loading" do
9289
let!(:links){
93-
[Link.create(:source => source, :target => kibble),
94-
Link.create(:source => source, :target => water)]
90+
[Link.create(source: source, target: kibble),
91+
Link.create(source: source, target: water)]
9592
}
9693
let(:source) { cat }
9794

@@ -105,8 +102,8 @@
105102

106103
context "When using a through relation to the links with eagar loading" do
107104
let!(:links){
108-
[Link.create(:source => source, :target => kibble),
109-
Link.create(:source => source, :target => water)]
105+
[Link.create(source: source, target: kibble),
106+
Link.create(source: source, target: water)]
110107
}
111108
let(:source) { dog }
112109

@@ -119,37 +116,37 @@
119116
end
120117

121118
context "When eagar loading the polymorphic association" do
122-
let(:link) { Link.create(:source_id => source.id, :source_type => source.class.to_s) }
119+
let(:link) { Link.create(source_id: source.id, source_type: source.class.to_s) }
123120
let(:source) { cat }
124121

125122
context "and when there are multiples sources" do
126-
let(:link_2) { Link.create(:source_id => source_2.id, :source_type => source_2.class.to_s) }
123+
let(:link_2) { Link.create(source_id: source_2.id, source_type: source_2.class.to_s) }
127124
let(:source_2) { dog }
128125
it "should be able to preload both associations" do
129-
links = Link.includes(:source).where(:id => [link.id, link_2.id]).order(:id)
126+
links = Link.includes(:source).where(id: [link.id, link_2.id]).order(:id)
130127
expect(links.first.source).to eql cat
131128
expect(links.last.source).to eql dog
132129
end
133130

134131
end
135132

136133
it "should be able to preload the association" do
137-
l = Link.includes(:source).where(:id => link.id).first
134+
l = Link.includes(:source).where(id: link.id).first
138135
expect(l.source).to eql cat
139136
end
140137

141138

142139
end
143140

144141
context "when the association is an STI table" do
145-
let(:link) { Link.create(:source => source, :target => whiskey) }
146-
let(:source) { Dog.create(:name => "Bela", :kind => "Dog", :owner => owner) }
142+
let(:link) { Link.create(source: source, target: whiskey) }
143+
let(:source) { Dog.create(name: "Bela", kind: "Dog", owner: owner) }
147144
it "should have the proper id, type and object for the source" do
148145
expect(link.source_id).to eql source.id
149146
expect(link.source_type).to eql "Animal"
150147
expect(link.source).to eql source
151148
end
152149
end
153150

154-
151+
context "when "
155152
end

spec/support/animal.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
class Animal < ActiveRecord::Base
2-
32
include PolymorphicIntegerType::Extensions
43

5-
belongs_to :owner, :class_name => "Person"
6-
has_many :source_links, :as => :source, :integer_type => true, :class_name => "Link"
7-
8-
9-
4+
belongs_to :owner, class_name: "Person"
5+
has_many :source_links, as: :source, integer_type: true, class_name: "Link"
106
end

spec/support/configuration.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
PolymorphicIntegerType::Mapping.configuration do |config|
2-
32
config.add :source, {0 => "Person", 1 => "Animal"}
43
config.add :target, {0 => "Food", 1 => "Drink"}
5-
64
end

spec/support/dog.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
class Dog < Animal
2-
3-
42
end

spec/support/drink.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
class Drink < ActiveRecord::Base
2-
32
include PolymorphicIntegerType::Extensions
43

5-
has_many :target_links, :as => :target, :integer_type => true, :class_name => "Link"
6-
7-
8-
4+
has_many :target_links, as: :target, integer_type: true, class_name: "Link"
95
end

spec/support/food.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
class Food < ActiveRecord::Base
2-
32
include PolymorphicIntegerType::Extensions
43

5-
has_many :target_links, :as => :target, :integer_type => true, :class_name => "Link"
6-
7-
4+
has_many :target_links, as: :target, integer_type: true, class_name: "Link"
85
end

spec/support/link.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
class Link < ActiveRecord::Base
2-
32
include PolymorphicIntegerType::Extensions
43

5-
belongs_to :source, :polymorphic => true, :integer_type => true
6-
belongs_to :target, :polymorphic => true, :integer_type => true
7-
4+
belongs_to :source, polymorphic: true, integer_type: true
5+
belongs_to :target, polymorphic: true, integer_type: true
86
end

spec/support/person.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
class Person < ActiveRecord::Base
2-
32
include PolymorphicIntegerType::Extensions
43

5-
has_many :pets, :class_name => "Animal", :foreign_key => :owner_id
6-
has_many :source_links, :as => :source, :integer_type => true, :class_name => "Link"
7-
8-
has_many :pet_source_links, :class_name => "Link", :through => :pets, :source => :source_links
9-
4+
has_many :pets, class_name: "Animal", foreign_key: :owner_id
5+
has_many :source_links, as: :source, integer_type: true, class_name: "Link"
106

7+
has_many :pet_source_links, class_name: "Link", through: :pets, source: :source_links
118
end

0 commit comments

Comments
 (0)