revolutionhealth-acts_as_seo_friendly 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
data/Rakefile CHANGED
@@ -1,12 +1,64 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
3
5
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
6
+ GEM = "acts_as_seo_friendly"
7
+ GEM_VERSION = "1.1.0"
8
+ AUTHOR = "Revolution Health"
9
+ EMAIL = "rails-trunk@revolutionhealth.com"
10
+ HOMEPAGE = %q{http://github.com/revolutionhealth/acts_as_seo_friendly}
11
+ SUMMARY = "provides a seo friendly version of field on a table"
12
+ DESCRIPTION = "provides a seo friendly version of field on a table"
5
13
 
6
- task :gemspec do
7
- gemspec_file = File.join(File.dirname(__FILE__), "#{GEM_NAME}.gemspec")
8
- `rake debug_gem > #{gemspec_file}`
9
- gemspec = File.readlines(gemspec_file)
10
- gemspec.delete_at(0)
11
- File.open(gemspec_file, "w+") {|f| f << gemspec.to_s() }
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = GEM
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = false
20
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
21
+ s.summary = SUMMARY
22
+ s.description = DESCRIPTION
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.rdoc_options = ["--main", "README"]
27
+
28
+
29
+ # Uncomment this to add a dependency
30
+ # s.add_dependency "foo"
31
+
32
+ s.require_path = 'lib'
33
+ s.autorequire = GEM
34
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,test, config}/**/*")
35
+ s.test_files = Dir.glob("{test}/**/*")
36
+ end
37
+
38
+ Rake::GemPackageTask.new(spec) do |pkg|
39
+ pkg.gem_spec = spec
40
+ end
41
+
42
+ desc "install the gem locally"
43
+ task :install => [:package] do
44
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
45
+ end
46
+
47
+ desc "create a gemspec file"
48
+ task :make_spec do
49
+ File.open("#{GEM}.gemspec", "w") do |file|
50
+ file.puts spec.to_ruby
51
+ end
52
+ end
53
+
54
+ require 'test/unit'
55
+
56
+ task :test do
57
+ runner = Test::Unit::AutoRunner.new(true)
58
+ runner.to_run << 'test'
59
+ runner.pattern = [/_test.rb$/]
60
+ exit if !runner.run
61
+ end
62
+
63
+ task :default => [:test, :package] do
12
64
  end
data/TODO ADDED
File without changes
@@ -120,8 +120,15 @@ module ActiveRecord
120
120
 
121
121
  result = nil
122
122
  if (count_seo_id_value != 0)
123
- last = count_seo_id_N_value
124
- result = last + 1
123
+ # +1 from current count of seo ids with similar format
124
+ result = count_seo_id_N_value + 1
125
+ # +1 until the seo id does not exist in the database
126
+ # The initial check is based on the counter above, so, in a rare case of another collision,
127
+ # the code shouldn't execute the find_by query that many times.
128
+ #
129
+ # For example, if there are 10000 rows that matches the format, the first check would be on 100001
130
+ # and not 1
131
+ result += 1 until self.class.send("find_by_#{seo_id_field}".to_sym, "#{seo_id_value}-#{result}").blank?
125
132
  end
126
133
  return result
127
134
  end
@@ -2,7 +2,7 @@ module ActsAsSeoFriendly #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+
4
+ silence_warnings do
5
+ require 'active_record'
6
+ end
7
+
8
+ module ActiveRecordTestHelper
9
+ def self.included(base)
10
+ ActiveRecord::Base.configurations = {'test' => {'adapter' => "sqlite3", "dbfile" => ":memory:"}}
11
+ end
12
+
13
+ def ar_setup
14
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
15
+ ActiveRecord::Base.logger.level = Logger::WARN
16
+ ActiveRecord::Base.logger.level = Logger::DEBUG if ENV['DEBUG_SQL'] == 'true'
17
+
18
+ ActiveRecord::Base.establish_connection
19
+ ActiveRecord::Base.connection.reconnect!
20
+ end
21
+
22
+ def ar_teardown
23
+ ActiveRecord::Base.connection.tables.each do |table|
24
+ ActiveRecord::Base.connection.drop_table(table)
25
+ end
26
+ ActiveRecord::Base.connection.disconnect!
27
+ end
28
+
29
+ end
@@ -2,17 +2,12 @@ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
  require 'ostruct'
3
3
 
4
4
  class TestActsAsSeoFriendly < Test::Unit::TestCase
5
- ActiveRecord::Base.configurations = {'test' => {'adapter' => "sqlite3", "dbfile" => ":memory:"}}
6
-
5
+ include ActiveRecordTestHelper
6
+
7
7
  def setup
8
- ActiveRecord::Base.logger = Logger.new(STDOUT)
9
- ActiveRecord::Base.logger.level = Logger::WARN
10
- ActiveRecord::Base.logger.level = Logger::DEBUG if ENV['DEBUG_SQL'] == 'true'
8
+ ar_setup()
11
9
 
12
- ActiveRecord::Base.establish_connection
13
- ActiveRecord::Base.connection.reconnect!
14
- ActiveRecord::Schema.define(:version => 1) do
15
-
10
+ ActiveRecord::Schema.define(:version => 1) do
16
11
  create_table :seo_test_models do |t|
17
12
  t.string :name
18
13
  t.timestamps
@@ -23,10 +18,7 @@ class TestActsAsSeoFriendly < Test::Unit::TestCase
23
18
 
24
19
  def teardown
25
20
  SeoTestModel.drop_seo_friendly_column()
26
- ActiveRecord::Base.connection.tables.each do |table|
27
- ActiveRecord::Base.connection.drop_table(table)
28
- end
29
- ActiveRecord::Base.connection.disconnect!
21
+ ar_teardown()
30
22
  end
31
23
 
32
24
  def test_id_generation
@@ -146,13 +138,26 @@ class TestActsAsSeoFriendly < Test::Unit::TestCase
146
138
 
147
139
  begin
148
140
  oil_short3 = SeoTestModel.create!(:name =>"oil")
149
- assert (oil_short3.seo_id.size <= 8)
141
+ assert(oil_short3.seo_id.size <= 8)
150
142
  ensure
151
143
  opts[:seo_friendly_id_limit] = orig_limit
152
144
  SeoTestModel.write_inheritable_attribute(:seo_friendly_options, opts)
153
145
  end
154
146
 
155
147
  end
148
+
149
+ def test_collision_with_original_seo_id
150
+ a = SeoTestModel.create!(:name => "a 1")
151
+ assert_equal('a-1', a.seo_id)
152
+ b = SeoTestModel.create!(:name => "a 1/2")
153
+ assert_equal('a-1-2', b.seo_id)
154
+ c = SeoTestModel.create!(:name => "a 1/4")
155
+ assert_equal('a-1-4', c.seo_id)
156
+ d = SeoTestModel.create!(:name => "a 1")
157
+ assert_equal('a-1-3', d.seo_id, "seo_id unique counter should be +1 of and existing seo_id that matches the format with the minimum counter value")
158
+ e = SeoTestModel.create!(:name => "a 1")
159
+ assert_equal('a-1-5', e.seo_id, "seo_id unique counter should be +1 of and existing seo_id that matches the format with the minimum counter value")
160
+ end
156
161
 
157
162
  private
158
163
  def create_seo_str(str)
data/test/test_helper.rb CHANGED
@@ -1,8 +1,8 @@
1
- RAILS_ENV = 'test'
1
+ RAILS_ENV = 'test' if !defined?(RAILS_ENV) || RAILS_ENV != 'test'
2
2
  require 'test/unit'
3
3
  require 'rubygems'
4
4
 
5
- require 'active_record'
5
+ require 'active_record_test_helper'
6
6
 
7
7
  require File.dirname(__FILE__) + '/../lib/acts_as_seo_friendly'
8
8
 
metadata CHANGED
@@ -1,70 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revolutionhealth-acts_as_seo_friendly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Revolution Health
8
- autorequire:
8
+ autorequire: acts_as_seo_friendly
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-16 00:00:00 -07:00
12
+ date: 2008-06-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: provides a seo friendly version of field on a table
17
- email:
18
- - opensource@revolutionhealth.com
17
+ email: rails-trunk@revolutionhealth.com
19
18
  executables: []
20
19
 
21
20
  extensions: []
22
21
 
23
22
  extra_rdoc_files:
24
- - History.txt
25
- - License.txt
26
- - Manifest.txt
27
- - PostInstall.txt
28
- - README.txt
29
- - website/index.txt
23
+ - README
24
+ - LICENSE
25
+ - TODO
30
26
  files:
31
- - History.txt
32
- - License.txt
33
- - Manifest.txt
34
- - PostInstall.txt
35
- - README.txt
27
+ - LICENSE
28
+ - README
36
29
  - Rakefile
37
- - acts_as_seo_friendly.gemspec
38
- - config/hoe.rb
39
- - config/requirements.rb
40
- - lib/acts_as_seo_friendly.rb
30
+ - TODO
31
+ - lib/acts_as_seo_friendly
41
32
  - lib/acts_as_seo_friendly/version.rb
42
- - script/console
43
- - script/destroy
44
- - script/generate
45
- - script/txt2html
46
- - setup.rb
47
- - tasks/deployment.rake
48
- - tasks/environment.rake
49
- - tasks/website.rake
33
+ - lib/acts_as_seo_friendly.rb
34
+ - test/active_record_test_helper.rb
50
35
  - test/seo_test_model.rb
51
36
  - test/seo_test_model_conditions.rb
52
37
  - test/test_acts_as_seo_friendly.rb
53
38
  - test/test_helper.rb
54
- - website/index.html
55
- - website/index.txt
56
- - website/javascripts/rounded_corners_lite.inc.js
57
- - website/stylesheets/screen.css
58
- - website/template.html.erb
59
- has_rdoc: true
60
- homepage: http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master
61
- post_install_message: |+
62
-
63
- For more information on acts_as_seo_friendly, see http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master
64
-
39
+ has_rdoc: false
40
+ homepage: http://github.com/revolutionhealth/acts_as_seo_friendly
41
+ post_install_message:
65
42
  rdoc_options:
66
43
  - --main
67
- - README.txt
44
+ - README
68
45
  require_paths:
69
46
  - lib
70
47
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -81,11 +58,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
58
  version:
82
59
  requirements: []
83
60
 
84
- rubyforge_project: acts_as_seo_friendly
85
- rubygems_version: 1.0.1
61
+ rubyforge_project:
62
+ rubygems_version: 1.2.0
86
63
  signing_key:
87
64
  specification_version: 2
88
65
  summary: provides a seo friendly version of field on a table
89
66
  test_files:
67
+ - test/active_record_test_helper.rb
68
+ - test/seo_test_model.rb
69
+ - test/seo_test_model_conditions.rb
90
70
  - test/test_acts_as_seo_friendly.rb
91
71
  - test/test_helper.rb
data/History.txt DELETED
@@ -1,4 +0,0 @@
1
- == 1.0.0 2008-06-13
2
-
3
- * 1 major enhancement:
4
- * Initial release
data/Manifest.txt DELETED
@@ -1,28 +0,0 @@
1
- History.txt
2
- License.txt
3
- Manifest.txt
4
- PostInstall.txt
5
- README.txt
6
- Rakefile
7
- acts_as_seo_friendly.gemspec
8
- config/hoe.rb
9
- config/requirements.rb
10
- lib/acts_as_seo_friendly.rb
11
- lib/acts_as_seo_friendly/version.rb
12
- script/console
13
- script/destroy
14
- script/generate
15
- script/txt2html
16
- setup.rb
17
- tasks/deployment.rake
18
- tasks/environment.rake
19
- tasks/website.rake
20
- test/seo_test_model.rb
21
- test/seo_test_model_conditions.rb
22
- test/test_acts_as_seo_friendly.rb
23
- test/test_helper.rb
24
- website/index.html
25
- website/index.txt
26
- website/javascripts/rounded_corners_lite.inc.js
27
- website/stylesheets/screen.css
28
- website/template.html.erb
data/PostInstall.txt DELETED
@@ -1,3 +0,0 @@
1
-
2
- For more information on acts_as_seo_friendly, see http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master
3
-
@@ -1,26 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{acts_as_seo_friendly}
3
- s.version = "1.1.0"
4
-
5
- s.specification_version = 2 if s.respond_to? :specification_version=
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Revolution Health"]
9
- s.date = %q{2008-06-16}
10
- s.description = %q{provides a seo friendly version of field on a table}
11
- s.email = ["opensource@revolutionhealth.com"]
12
- s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "website/index.txt"]
13
- s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "acts_as_seo_friendly.gemspec", "config/hoe.rb", "config/requirements.rb", "lib/acts_as_seo_friendly.rb", "lib/acts_as_seo_friendly/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/seo_test_model.rb", "test/seo_test_model_conditions.rb", "test/test_acts_as_seo_friendly.rb", "test/test_helper.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master}
16
- s.post_install_message = %q{
17
- For more information on acts_as_seo_friendly, see http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master
18
-
19
- }
20
- s.rdoc_options = ["--main", "README.txt"]
21
- s.require_paths = ["lib"]
22
- s.rubyforge_project = %q{acts_as_seo_friendly}
23
- s.rubygems_version = %q{1.1.1}
24
- s.summary = %q{provides a seo friendly version of field on a table}
25
- s.test_files = ["test/test_acts_as_seo_friendly.rb", "test/test_helper.rb"]
26
- end
data/config/hoe.rb DELETED
@@ -1,73 +0,0 @@
1
- require 'acts_as_seo_friendly/version'
2
-
3
- AUTHOR = 'Revolution Health' # can also be an array of Authors
4
- EMAIL = "opensource@revolutionhealth.com"
5
- DESCRIPTION = "provides a seo friendly version of field on a table"
6
- GEM_NAME = 'acts_as_seo_friendly' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'acts_as_seo_friendly' # The unix name for your project
8
- HOMEPATH = "http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master"
9
- DOWNLOAD_PATH = "http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master"
10
- EXTRA_DEPENDENCIES = [
11
- # ['activesupport', '>= 1.3.1']
12
- ] # An array of rubygem dependencies [name, version]
13
-
14
- @config_file = "~/.rubyforge/user-config.yml"
15
- @config = nil
16
- RUBYFORGE_USERNAME = "unknown"
17
- def rubyforge_username
18
- unless @config
19
- begin
20
- @config = YAML.load(File.read(File.expand_path(@config_file)))
21
- rescue
22
- puts <<-EOS
23
- ERROR: No rubyforge config file found: #{@config_file}
24
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
- - See http://newgem.rubyforge.org/rubyforge.html for more details
26
- EOS
27
- exit
28
- end
29
- end
30
- RUBYFORGE_USERNAME.replace @config["username"]
31
- end
32
-
33
-
34
- REV = nil
35
- # UNCOMMENT IF REQUIRED:
36
- # REV = YAML.load(`svn info`)['Revision']
37
- VERS = ActsAsSeoFriendly::VERSION::STRING + (REV ? ".#{REV}" : "")
38
- RDOC_OPTS = ['--quiet', '--title', 'acts_as_seo_friendly documentation',
39
- "--opname", "index.html",
40
- "--line-numbers",
41
- "--main", "README",
42
- "--inline-source"]
43
-
44
- class Hoe
45
- def extra_deps
46
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
- @extra_deps
48
- end
49
- end
50
-
51
- # Generate all the Rake tasks
52
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
- $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
- p.developer(AUTHOR, EMAIL)
55
- p.description = DESCRIPTION
56
- p.summary = DESCRIPTION
57
- p.url = HOMEPATH
58
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
- p.test_globs = ["test/**/test_*.rb"]
60
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
-
62
- # == Optional
63
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
- #p.extra_deps = EXTRA_DEPENDENCIES
65
-
66
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
- end
68
-
69
- CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
- $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
- $hoe.rsync_args = '-av --delete --ignore-errors'
73
- $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""