stringex 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- if url_owners.size > 0
77
- return unless url_owners.map { |o| o.send(url_attribute) }.include?(base_url)
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.detect{|u| u.send(url_attribute) == "#{base_url}-#{n}"}
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stringex}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Russell Norris"]
@@ -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")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Norris