rewritten 0.12.0 → 0.12.1
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.
- checksums.yaml +4 -4
- data/lib/rewritten/document.rb +10 -7
- data/lib/rewritten/version.rb +1 -1
- data/test/rewritten/document_test.rb +12 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34a5c63d94e26e835807498f850cf45eecb6a846
|
4
|
+
data.tar.gz: dc27dfb93fd4a561fde220961a6d1d09c5019268
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe1017ab7ec13d289b1f2107f4f0931b878c356686aadad6018cf933a646c0b0a7d98696098600bfc2b7ee487a286b7a6906f057d58eead5428394e77163667
|
7
|
+
data.tar.gz: 84c441c885be0a95a9a5e00a5cbdaa068fd24264c8c16c8afe7348ae1f3cbb3d739286a066d7076f5c1d900c2b94a6d21f29c24832da8fe0717ff00b402db749
|
data/lib/rewritten/document.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
module Rewritten
|
2
2
|
module Document
|
3
3
|
|
4
|
-
def rewritten_url=(new_translation)
|
5
|
-
Rewritten.add_translation(new_translation, url_for(self))
|
6
|
-
end
|
7
4
|
|
8
5
|
def rewritten_url
|
9
6
|
return "" unless persisted?
|
10
|
-
Rewritten.get_current_translation(
|
7
|
+
Rewritten.get_current_translation(polymorphic_url(self, :only_path => true))
|
8
|
+
end
|
9
|
+
|
10
|
+
def rewritten_url=(new_url)
|
11
|
+
if !new_url.nil? && new_url != "" && new_url != rewritten_url
|
12
|
+
Rewritten.add_translation(new_url, polymorphic_url(self, :only_path => true))
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
16
|
def rewritten_urls
|
14
17
|
return [] unless persisted?
|
15
|
-
Rewritten.get_all_translations(
|
18
|
+
Rewritten.get_all_translations(polymorphic_url(self, :only_path => true))
|
16
19
|
end
|
17
20
|
|
18
21
|
def has_rewritten_url?
|
19
|
-
Rewritten.exist_translation_for?(
|
22
|
+
Rewritten.exist_translation_for?(polymorphic_url(self, :only_path => true))
|
20
23
|
end
|
21
24
|
|
22
25
|
def remove_rewritten_urls
|
23
|
-
Rewritten.remove_all_translations(
|
26
|
+
Rewritten.remove_all_translations(polymorphic_url(self, :only_path => true))
|
24
27
|
end
|
25
28
|
|
26
29
|
end
|
data/lib/rewritten/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe Rewritten::Document do
|
|
7
7
|
include Rewritten::Document
|
8
8
|
end
|
9
9
|
@instance = Product.new
|
10
|
-
def @instance.
|
10
|
+
def @instance.polymorphic_url(object, options={}); '/products/123'; end
|
11
11
|
def @instance.persisted?; true; end
|
12
12
|
end
|
13
13
|
|
@@ -35,7 +35,6 @@ describe Rewritten::Document do
|
|
35
35
|
Rewritten.add_translation('/foo/baz', '/products/123')
|
36
36
|
|
37
37
|
@instance.rewritten_urls.must_equal ['/foo/bar', '/foo/baz']
|
38
|
-
|
39
38
|
end
|
40
39
|
|
41
40
|
it 'must add a new translation' do
|
@@ -52,6 +51,17 @@ describe Rewritten::Document do
|
|
52
51
|
@instance.rewritten_urls.must_equal []
|
53
52
|
end
|
54
53
|
|
54
|
+
it 'must won\'t add blank and similar translations' do
|
55
|
+
@instance.rewritten_url = '/foo/bar'
|
56
|
+
@instance.rewritten_urls.must_equal ['/foo/bar']
|
57
|
+
@instance.rewritten_url = nil
|
58
|
+
@instance.rewritten_urls.must_equal ['/foo/bar']
|
59
|
+
@instance.rewritten_url = ""
|
60
|
+
@instance.rewritten_urls.must_equal ['/foo/bar']
|
61
|
+
@instance.rewritten_url = "/foo/bar"
|
62
|
+
@instance.rewritten_urls.must_equal ['/foo/bar']
|
63
|
+
end
|
64
|
+
|
55
65
|
end
|
56
66
|
|
57
67
|
|