objectreload-permalinks 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/permalinks.rb +1 -1
- data/objectreload-permalinks.gemspec +1 -1
- data/test/permalinks_test.rb +12 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/permalinks.rb
CHANGED
@@ -6,7 +6,7 @@ module Permalinks
|
|
6
6
|
module ClassMethods
|
7
7
|
def has_permalink(field = :name)
|
8
8
|
define_method(:to_param) do
|
9
|
-
"#{id}-#{send(field).to_s.downcase.gsub(/[^[:alnum:]]/,'-')}".gsub(/-{2,}/, '-')
|
9
|
+
"#{id}-#{send(field).to_s.strip.downcase.gsub(/[^[:alnum:]]/,'-')}".gsub(/-{2,}/, '-')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{objectreload-permalinks}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mateusz Drozdzynski", "Ewa Limanowka"]
|
data/test/permalinks_test.rb
CHANGED
@@ -14,18 +14,27 @@ class CountryTest < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context "country name with a lot of spaces" do
|
17
|
+
context "country name with a lot of white spaces" do
|
18
18
|
should "return permalink" do
|
19
19
|
@country.name = "United Kingdom "
|
20
|
-
@country.save
|
20
|
+
@country.save!
|
21
21
|
assert_equal "#{@country.id}-united-kingdom", @country.to_param
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
context "country with id equal nil" do
|
26
|
+
should "return permalink" do
|
27
|
+
@country.name = "2-tratata"
|
28
|
+
@country.id = nil
|
29
|
+
@country.save!
|
30
|
+
assert_equal "#{@country.id}-2-tratata", @country.to_param
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
context "country name with capital letters" do
|
26
35
|
should "return permalink" do
|
27
36
|
@country.name = " USA "
|
28
|
-
@country.save
|
37
|
+
@country.save!
|
29
38
|
assert_equal "#{@country.id}-usa", @country.to_param
|
30
39
|
end
|
31
40
|
end
|