seofy 0.0.4 → 0.0.5

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.
@@ -12,7 +12,16 @@ module Seofy
12
12
  end
13
13
 
14
14
  def set_seofy_slug(inst)
15
- inst.send("#{column}=", ::Seofy::Encoders::Base36.random(self.length))
15
+ slug_exist = true
16
+ while slug_exist
17
+ random = ::Seofy::Encoders::Base36.random(self.length)
18
+ if inst.class.exists?(["#{column} = ?", random])
19
+ slug_exist = true
20
+ else
21
+ inst.send("#{column}=", random)
22
+ slug_exist = false
23
+ end
24
+ end
16
25
  end
17
26
  end
18
27
  end
@@ -1,3 +1,3 @@
1
1
  module Seofy
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -12,6 +12,7 @@ describe Seofy::Adapters::Base36 do
12
12
  stub = Object.new
13
13
  ::Seofy::Encoders::Base36.should_receive(:random).with(3).and_return("abc")
14
14
  stub.should_receive("slug=").with("abc")
15
+ stub.class.should_receive(:exists?).with(['slug = ?', "abc"]).and_return(false)
15
16
  adapter.set_seofy_slug(stub)
16
17
  end
17
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seofy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Allen Wei