stringex 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/lucky_sneaks/acts_as_url.rb +3 -5
- data/stringex.gemspec +1 -1
- data/test/acts_as_url_test.rb +8 -0
- metadata +1 -1
@@ -73,15 +73,13 @@ module LuckySneaks
|
|
73
73
|
conditions << send(self.class.scope_for_url)
|
74
74
|
end
|
75
75
|
url_owners = self.class.find(:all, :conditions => conditions)
|
76
|
-
|
77
|
-
|
76
|
+
write_attribute url_attribute, base_url
|
77
|
+
if url_owners.any?{|owner| owner.send(url_attribute) == base_url}
|
78
78
|
n = 1
|
79
|
-
while url_owners.
|
79
|
+
while url_owners.any?{|owner| owner.send(url_attribute) == "#{base_url}-#{n}"}
|
80
80
|
n = n.succ
|
81
81
|
end
|
82
82
|
write_attribute url_attribute, "#{base_url}-#{n}"
|
83
|
-
else
|
84
|
-
write_attribute url_attribute, base_url
|
85
83
|
end
|
86
84
|
end
|
87
85
|
end
|
data/stringex.gemspec
CHANGED
data/test/acts_as_url_test.rb
CHANGED
@@ -109,6 +109,14 @@ class ActsAsUrlTest < Test::Unit::TestCase
|
|
109
109
|
assert_equal "twonique-1", @other_doc2.url
|
110
110
|
end
|
111
111
|
|
112
|
+
def test_should_create_unique_url_when_partial_url_already_exists
|
113
|
+
@doc = Document.create!(:title => "House Farms")
|
114
|
+
@other_doc = Document.create!(:title => "House Farm")
|
115
|
+
|
116
|
+
assert_equal "house-farms", @doc.url
|
117
|
+
assert_equal "house-farm", @other_doc.url
|
118
|
+
end
|
119
|
+
|
112
120
|
def test_should_scope_uniqueness
|
113
121
|
@moc = Mocument.create!(:title => "Mocumentary", :other => "I dunno why but I don't care if I'm unique")
|
114
122
|
@other_moc = Mocument.create!(:title => "Mocumentary")
|