vanity_slug 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d47176486a92662a7b2ba26cb421902ee7835c2e
4
+ data.tar.gz: c0cc87e0d6c97e464b9c029ce46dcdd73c41a661
5
+ SHA512:
6
+ metadata.gz: f760ada2b91ae7639922cbcd19bcd2a68afeafc7e5a9c9fb490193b01f2e46b2ecf98b854d6d651a5baf047b3a76051f83356367be49e69985a04e794d883914
7
+ data.tar.gz: 1c346ca98738d438e323e74401b0a83cc578fc62dd46e12b1e5629fe4aba76d98e78abf24b660045cd96fe599028910dd68713b474501ee6561110fcc50b48f5
data/Gemfile CHANGED
@@ -5,8 +5,8 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'rspec'
8
- gem 'debugger'
9
8
  gem 'activerecord'
10
9
  gem 'sqlite3'
11
- gem 'simplecov', require: false
10
+ gem 'rake'
11
+ gem 'coveralls'
12
12
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # VanitySlug
2
2
 
3
+ [![Test Coverage](https://coveralls.io/repos/nickmerwin/vanity_slug/badge.png?branch=master)](https://coveralls.io/r/nickmerwin/vanity_slug)
4
+
3
5
  Add unique vanity urls to any model without use of redirects. Middleware matches routes that don't resolve with the Rails router and checks if they match a slug from any vanity-slug enabled model. If found, the `env["PATH_INFO"]` is changed like so:
4
6
 
5
7
  Given a Post with slug "my-post-title" and id 1, and a Category with slug "the-category" and id 2:
@@ -87,3 +89,4 @@ Use to scope the finder based on rack env, i.e. host parameter. Should return a
87
89
  3. Commit your changes (`git commit -am 'Add some feature'`)
88
90
  4. Push to the branch (`git push origin my-new-feature`)
89
91
  5. Create new Pull Request
92
+
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:rspec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ spec.rspec_opts = ['-cfs --backtrace']
8
+ end
9
+
10
+ task :default => :rspec
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ database:
2
+ override:
3
+ - echo "skipping database steps"
@@ -61,11 +61,11 @@ ActiveSupport.on_load :active_record do
61
61
  slug_to_check = send(self.class.slug_field)
62
62
 
63
63
  exists = VanitySlug.classes.any? do |klass|
64
- scope = klass.has_vanity_slug_opts[:uniqueness_scope]
64
+ scope = klass.has_vanity_slug_opts[:uniqueness_scope]
65
65
  conditions = scope ? { scope => send(scope) } : {}
66
66
 
67
- finder = klass.where(conditions.merge({
68
- klass.slug_field => slug_to_check
67
+ finder = klass.where(conditions.merge({
68
+ klass.slug_field => slug_to_check
69
69
  }))
70
70
 
71
71
  finder = finder.where("id != ?", self.id) if klass.to_s == self.class.to_s
@@ -82,10 +82,10 @@ ActiveSupport.on_load :active_record do
82
82
  end
83
83
 
84
84
  def vanity_slug_exists?(potential_slug)
85
- return true if VanitySlug.check_route_collision(potential_slug)
85
+ return true if VanitySlug.check_route_collision(potential_slug)
86
86
 
87
87
  VanitySlug.classes.any? do |klass|
88
- scope = klass.has_vanity_slug_opts[:uniqueness_scope]
88
+ scope = klass.has_vanity_slug_opts[:uniqueness_scope]
89
89
  conditions = scope ? { scope => send(scope) } : {}
90
90
  klass.exists? conditions.merge({ klass.slug_field => potential_slug })
91
91
  end
@@ -96,7 +96,7 @@ ActiveSupport.on_load :active_record do
96
96
  class << self
97
97
  attr_accessor :path_scope
98
98
  attr_accessor :classes
99
-
99
+
100
100
  def add_class(klass)
101
101
  @classes ||= []
102
102
  @classes << klass unless @classes.include?(klass)
@@ -116,14 +116,14 @@ ActiveSupport.on_load :active_record do
116
116
  .first
117
117
  end
118
118
  return false unless obj
119
-
119
+
120
120
  obj.get_vanity_action + File.extname(path)
121
121
  end
122
122
 
123
123
  def check_route_collision(path)
124
124
  if defined?(Rails)
125
125
  begin
126
- return true if Rails.application.routes.recognize_path(path)
126
+ return true if Rails.application.routes.recognize_path(path) || Rails.application.routes.recognize_path(path, method: :post)
127
127
  rescue ActionController::RoutingError
128
128
  false
129
129
  end
@@ -1,3 +1,3 @@
1
1
  module VanitySlug
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- require 'simplecov'
5
- SimpleCov.start
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
6
 
7
7
  require 'active_support/all'
8
8
  require 'vanity_slug'
@@ -17,8 +17,8 @@ RSpec.configure do |config|
17
17
  end
18
18
 
19
19
  def silence
20
- return yield if ENV['silence'] == 'false'
21
-
20
+ return yield if ENV['silence'] == 'false' || !defined?(silence_stream)
21
+
22
22
  silence_stream(STDOUT) do
23
23
  yield
24
24
  end
@@ -6,7 +6,7 @@ VanitySlug.path_scope = Proc.new{|env|
6
6
  }
7
7
 
8
8
  class Post < ActiveRecord::Base
9
- attr_accessible :title, :site
9
+ attr_accessor :title, :site
10
10
 
11
11
  has_vanity_slug field_to_slug: :title,
12
12
  uniqueness_scope: :site_id
@@ -15,16 +15,16 @@ class Post < ActiveRecord::Base
15
15
  end
16
16
 
17
17
  class Category < ActiveRecord::Base
18
- attr_accessible :name, :site
18
+ attr_accessor :name, :site
19
19
 
20
- has_vanity_slug action: "/categories/:id/slug",
20
+ has_vanity_slug action: "/categories/:id/slug",
21
21
  slug_field: :permalink
22
22
 
23
23
  belongs_to :site
24
24
  end
25
25
 
26
26
  class Site < ActiveRecord::Base
27
- attr_accessible :domain
27
+ attr_accessor :domain
28
28
  end
29
29
 
30
30
  describe VanitySlug do
@@ -91,4 +91,4 @@ describe VanitySlug do
91
91
  it { @post_1.should be_valid }
92
92
  it { @post_1.title.should eq new_title }
93
93
  end
94
- end
94
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity_slug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nick Merwin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: root level Vanity Slug for any model
15
14
  email:
@@ -18,11 +17,12 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
20
+ - ".gitignore"
22
21
  - Gemfile
23
22
  - LICENSE.txt
24
23
  - README.md
25
24
  - Rakefile
25
+ - circle.yml
26
26
  - lib/vanity_slug.rb
27
27
  - lib/vanity_slug/active_record.rb
28
28
  - lib/vanity_slug/railtie.rb
@@ -34,27 +34,26 @@ files:
34
34
  - vanity_slug.gemspec
35
35
  homepage: https://github.com/nickmerwin/vanity_slug
36
36
  licenses: []
37
+ metadata: {}
37
38
  post_install_message:
38
39
  rdoc_options: []
39
40
  require_paths:
40
41
  - lib
41
42
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
43
  requirements:
44
- - - ! '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
48
  requirements:
50
- - - ! '>='
49
+ - - ">="
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  requirements: []
54
53
  rubyforge_project:
55
- rubygems_version: 1.8.23
54
+ rubygems_version: 2.5.2
56
55
  signing_key:
57
- specification_version: 3
56
+ specification_version: 4
58
57
  summary: easily add vanity slugs
59
58
  test_files:
60
59
  - spec/spec_helper.rb