acts_more_seo 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -9,4 +9,6 @@
9
9
  = Version 0.2.3
10
10
  * Major bug fixes, API changes
11
11
  = Version 0.2.4
12
- Backward compatibility improvements
12
+ Backward compatibility improvements
13
+ = Version 0.2.5
14
+ * Using ID when to_url returns same string as existing (conflicts)
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('acts_more_seo', '0.2.4') do |p|
6
+ Echoe.new('acts_more_seo', '0.2.5') do |p|
7
7
  p.description = "Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better"
8
8
  p.url = "https://github.com/mensfeld/Css-Image-Embedder"
9
9
  p.author = "Maciej Mensfeld"
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{acts_more_seo}
5
- s.version = "0.2.4"
5
+ s.version = "0.2.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [%q{Maciej Mensfeld}]
9
- s.date = %q{2011-11-04}
9
+ s.date = %q{2011-11-07}
10
10
  s.description = %q{Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better}
11
11
  s.email = %q{maciej@mensfeld.pl}
12
12
  s.extra_rdoc_files = [%q{CHANGELOG.rdoc}, %q{README.md}, %q{lib/acts_more_seo.rb}, %q{lib/string_ext.rb}]
data/lib/acts_more_seo.rb CHANGED
@@ -64,7 +64,12 @@ module Acts
64
64
  if self.seo_use_id
65
65
  to_url
66
66
  else
67
- seo_text_part.length > 0 ? seo_text_part : "#{self.id}"
67
+ seo_link = seo_text_part.length > 0 ? seo_text_part : "#{self.id}"
68
+ if !self.class.where("seo_url = ? AND id != ?", seo_link, self.id).limit(1).empty?
69
+ to_url
70
+ else
71
+ seo_link
72
+ end
68
73
  end
69
74
  end
70
75
 
@@ -21,6 +21,7 @@ end
21
21
 
22
22
  describe CoolElement do
23
23
  subject { CoolElement }
24
+ before(:each){ subject.destroy_all }
24
25
 
25
26
  context "when we have a class which has use_id => true" do
26
27
  it "should find element unless id is corrupted" do
@@ -56,6 +57,7 @@ end
56
57
 
57
58
  describe CoolerElement do
58
59
  subject { CoolerElement }
60
+ before(:each){ subject.destroy_all }
59
61
 
60
62
  context "when there is no name" do
61
63
  it "should return only id" do
@@ -92,6 +94,7 @@ end
92
94
 
93
95
  describe SpecialElement do
94
96
  subject { SpecialElement }
97
+ before(:each){ subject.destroy_all }
95
98
 
96
99
  context "when there is no name" do
97
100
  context "but surname and title exists" do
@@ -120,12 +123,13 @@ end
120
123
 
121
124
  describe BestElement do
122
125
  subject { BestElement }
126
+ before(:each){ subject.destroy_all }
123
127
 
124
128
  context "when there is no surname" do
125
129
  context "but surname and title exists" do
126
130
  it "should return nice looking url " do
127
131
  a = subject.create({:name => 'mensfeld', :title => 'test abc'})
128
- a.to_seo.should eql("mensfeld-test-abc")
132
+ a.seo_url.should eql("mensfeld-test-abc")
129
133
  a.seo_url.should eql("mensfeld-test-abc")
130
134
  end
131
135
  end
@@ -135,7 +139,7 @@ describe BestElement do
135
139
  context "but surname and title exists" do
136
140
  it "should return nice looking url " do
137
141
  a = subject.create({:surname => 'mensfeld', :title => 'test abc'})
138
- a.to_seo.should eql("mensfeld-test-abc")
142
+ a.seo_url.should eql("mensfeld-test-abc")
139
143
  a.reload
140
144
  a.seo_url.should eql("mensfeld-test-abc")
141
145
  end
@@ -144,7 +148,7 @@ describe BestElement do
144
148
  context "and no other param" do
145
149
  it "should return only id" do
146
150
  a = subject.create()
147
- a.to_seo.should eql("#{a.id}")
151
+ a.seo_url.should eql("#{a.id}")
148
152
  a.reload
149
153
  a.seo_url.should eql("#{a.id}")
150
154
  end
@@ -154,7 +158,7 @@ describe BestElement do
154
158
  context "when there are all the params" do
155
159
  it "should return nice url" do
156
160
  a = subject.create({:name => 'maciej', :surname => 'mensfeld', :title => 'test abc'})
157
- a.to_seo.should eql("maciej-mensfeld-test-abc")
161
+ a.seo_url.should eql("maciej-mensfeld-test-abc")
158
162
  a.reload
159
163
  a.seo_url.should eql("maciej-mensfeld-test-abc")
160
164
  end
@@ -163,7 +167,7 @@ describe BestElement do
163
167
  context "when we have a class which has use_id => false" do
164
168
  it "should find element only when seo_url is same (or by id)" do
165
169
  a = subject.create(:name => 'bla bla bla')
166
- subject.find_by_seo(a.to_seo).should eql(a)
170
+ subject.find_by_seo(a.seo_url).should eql(a)
167
171
  lambda { subject.find_by_seo("#{a.to_param}aaa") }.should raise_error(ActiveRecord::RecordNotFound)
168
172
  end
169
173
  end
@@ -171,12 +175,46 @@ describe BestElement do
171
175
  context "when updating object" do
172
176
  it "should have refreshed seo_url" do
173
177
  a = subject.create({:name => 'mensfeld', :title => 'test abc'})
174
- a.to_seo.should eql("mensfeld-test-abc")
178
+ a.seo_url.should eql("mensfeld-test-abc")
175
179
  a.name = 'kowalski'
176
180
  a.save
177
- a.to_seo.should eql("kowalski-test-abc")
181
+ a.seo_url.should eql("kowalski-test-abc")
178
182
  subject.find_by_seo("kowalski-test-abc").should eql(a)
179
183
  end
180
184
  end
181
185
 
186
+ context "when we have two objects" do
187
+ it "should assing to the second - seo url with id" do
188
+ a = subject.create({:name => 'mensfeld', :title => 'test abc'})
189
+ b = subject.create({:name => 'mensfeld ', :title => 'test abc'})
190
+ a.seo_url.should eql("mensfeld-test-abc")
191
+ b.reload
192
+ b.seo_url.should eql("#{b.id}-mensfeld-test-abc")
193
+ end
194
+
195
+ context "and we change name in a second one" do
196
+ it "should add na id if necessery" do
197
+ a = subject.create({:name => 'mensfeld', :title => 'test abc'})
198
+ b = subject.create({:name => 'mensfeld2 ', :title => 'test abc'})
199
+ a.seo_url.should eql("mensfeld-test-abc")
200
+ b.seo_url.should eql("mensfeld2-test-abc")
201
+ b.name = 'mensfeld'
202
+ b.save!
203
+ b.reload
204
+ b.seo_url.should eql("#{b.id}-mensfeld-test-abc")
205
+ end
206
+
207
+ it "should not add id if not necessery" do
208
+ a = subject.create({:name => 'mensfeld', :title => 'test abc'})
209
+ b = subject.create({:name => 'mensfeld2 ', :title => 'test abc'})
210
+ a.seo_url.should eql("mensfeld-test-abc")
211
+ b.seo_url.should eql("mensfeld2-test-abc")
212
+ b.name = 'mensfeld3'
213
+ b.save!
214
+ b.reload
215
+ b.seo_url.should eql("mensfeld3-test-abc")
216
+ end
217
+ end
218
+ end
219
+
182
220
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_more_seo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-04 00:00:00.000000000Z
12
+ date: 2011-11-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &26120860 !ruby/object:Gem::Requirement
16
+ requirement: &17432380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *26120860
24
+ version_requirements: *17432380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: active_record
27
- requirement: &26120380 !ruby/object:Gem::Requirement
27
+ requirement: &17431920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *26120380
35
+ version_requirements: *17431920
36
36
  description: Gem makes your ActiveRecord models more SEO friendly. Changes URL to
37
37
  look way better
38
38
  email: maciej@mensfeld.pl