rewritten 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4df6b29c36a9d6da1c0cc658f49a3f9d4a9f4d5
4
- data.tar.gz: 4274875b1c6dd086e738f164c33fbf1184684e7a
3
+ metadata.gz: 34a5c63d94e26e835807498f850cf45eecb6a846
4
+ data.tar.gz: dc27dfb93fd4a561fde220961a6d1d09c5019268
5
5
  SHA512:
6
- metadata.gz: 2bc012992fd582dd180b35551a00d0b994069b118cee7d307129939f69670f7fe584c66072aaa6764fbebc647929630110e829e0e664571c8841dd8cb163d0e5
7
- data.tar.gz: a7054b44d16800e07edf0261b3e2215a3eabc04252869ed168f01a8142895756f90e6476f519aab3d69c5fbd3e625d2105ae6b05b2fb41bcbb362570abec7f22
6
+ metadata.gz: afe1017ab7ec13d289b1f2107f4f0931b878c356686aadad6018cf933a646c0b0a7d98696098600bfc2b7ee487a286b7a6906f057d58eead5428394e77163667
7
+ data.tar.gz: 84c441c885be0a95a9a5e00a5cbdaa068fd24264c8c16c8afe7348ae1f3cbb3d739286a066d7076f5c1d900c2b94a6d21f29c24832da8fe0717ff00b402db749
@@ -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(url_for(self))
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(url_for(self))
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?(url_for(self))
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(url_for(self))
26
+ Rewritten.remove_all_translations(polymorphic_url(self, :only_path => true))
24
27
  end
25
28
 
26
29
  end
@@ -1,4 +1,4 @@
1
1
  module Rewritten
2
- VERSION = "0.12.0"
2
+ VERSION = "0.12.1"
3
3
  end
4
4
 
@@ -7,7 +7,7 @@ describe Rewritten::Document do
7
7
  include Rewritten::Document
8
8
  end
9
9
  @instance = Product.new
10
- def @instance.url_for(object); '/products/123'; end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rewritten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Rubarth