slugworth 1.2.0 → 1.2.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: a77159f292434b785943b273df3105db32acb74c
4
- data.tar.gz: 9b5ba418ef641c443d65812907b537ea54c5b11b
3
+ metadata.gz: 29c5a2617fdb5cb5bfebeb4545eeb25e19833dba
4
+ data.tar.gz: 4667dd9a4eab4e2934a22694fe730bb239da6f60
5
5
  SHA512:
6
- metadata.gz: 75f31bc79dc40409230b3350c377ff04f90430d21ec0b0161300a8c3816408f65b715cae1b6d499629a51bfa6a70c9b1f673af7ac4aec2afd91a133cfaa8573d
7
- data.tar.gz: bbd860dbb13e3f4abe7a9584d19616334ead8a062226041633536e2090eefdfa4e71fe2161779a7ce3f63d537df0997d16128816d314575088dfccdf125fb28e
6
+ metadata.gz: 2695d24b686191d58b56ffd5e04e2083b5cc059be663fc6a5a433a096de361a9a060b339f8f67471dcae66439bc5004026a02b69ad502a9cfed69544f0c34473
7
+ data.tar.gz: 112887759a1197cbc69e74e06597cb5ae5f062a4143b31a09c31ac9883f2334d2610d22ae4553201c9eed94928e66459f7aefb27a26a96a68eafe32a106ba97b
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1
4
+
5
+ - Bug fix for slug generation on a slug attribute that is nil
6
+
3
7
  ## 1.2.0
4
8
 
5
9
  - Uniqueness scoping for a slug
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  ![Slugworth](http://f.cl.ly/items/3T1K3g040S0u2l0G0d3V/slugworth_header.png)
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/slugworth.png)](http://badge.fury.io/rb/sluggle)
4
- [![Build Status](https://travis-ci.org/mattpolito/slugworth.png?branch=master)](https://travis-ci.org/mattpolito/slugworth)
5
- [![Code Climate](https://codeclimate.com/github/mattpolito/slugworth.png)](https://codeclimate.com/github/mattpolito/slugworth)
3
+ [![Gem Version](http://img.shields.io/gem/v/slugworth.svg?style=flat)](http://badge.fury.io/rb/slugworth)
4
+ [![Build Status](http://img.shields.io/travis/mattpolito/slugworth/master.svg?style=flat)](https://travis-ci.org/mattpolito/slugworth)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/mattpolito/slugworth.svg?style=flat)](https://codeclimate.com/github/mattpolito/slugworth)
6
6
 
7
7
  Simple slug functionality for your ActiveRecord objects
8
8
 
@@ -41,12 +41,12 @@ class User < ActiveRecord::Base
41
41
  end
42
42
  ```
43
43
 
44
- After you `include` the `Slugworth` module, all you need to do is declare what method will be used to create the slug. The method passed to `slugged_with` will then be paramterized.
44
+ After you `include` the `Slugworth` module, all you need to do is declare what method will be used to create the slug. The method passed to `slugged_with` will then be parameterized.
45
45
 
46
46
  This provides most of the default slug functionality you would need.
47
47
 
48
48
  * Finders `.find_by_slug` & `.find_by_slug!` are provided. This will, of course, do what you expect and find a single record by the slug attribute provided.
49
- * `#to_param` has been defined as a paramaterized version of the attribute declared to `slugged_with`.
49
+ * `#to_param` has been defined as a parameterized version of the attribute declared to `slugged_with`.
50
50
  * Validations stating that `slug` is present and unique in the database.
51
51
 
52
52
  ### Scoping uniqueness
@@ -5,15 +5,15 @@ module Slugworth
5
5
 
6
6
  included do
7
7
  cattr_accessor :slug_attribute, :slug_scope, :slug_incremental, :slug_updatable
8
- before_validation(:add_slug)
8
+ before_validation(:add_slug, if: :slug_attribute_value)
9
9
  end
10
10
 
11
11
  module ClassMethods
12
- def slugged_with(slug_attribute, opts={})
13
- self.slug_attribute = slug_attribute
14
- self.slug_scope = opts.delete(:scope)
12
+ def slugged_with(slug_attribute, opts = {})
13
+ self.slug_attribute = slug_attribute
14
+ self.slug_scope = opts.delete(:scope)
15
15
  self.slug_incremental = opts.delete(:incremental)
16
- self.slug_updatable = opts.delete(:updatable)
16
+ self.slug_updatable = opts.delete(:updatable)
17
17
  validates_uniqueness_of :slug, scope: slug_scope
18
18
  end
19
19
 
@@ -29,6 +29,7 @@ module Slugworth
29
29
  def to_param; slug; end
30
30
 
31
31
  private
32
+
32
33
  def add_slug
33
34
  self.slug = processed_slug if generate_slug?
34
35
  end
@@ -37,12 +38,16 @@ module Slugworth
37
38
  !slug.present? || slug_updatable && changes[slug_attribute].present?
38
39
  end
39
40
 
41
+ def slug_attribute_value
42
+ public_send(slug_attribute)
43
+ end
44
+
40
45
  def processed_slug
41
- slug_incremental ? process_incremental_slug : parameterized_slug
46
+ slug_incremental ? process_incremental_slug : parameterized_slug
42
47
  end
43
48
 
44
49
  def parameterized_slug
45
- public_send(slug_attribute).parameterize
50
+ slug_attribute_value.parameterize
46
51
  end
47
52
 
48
53
  def process_incremental_slug
@@ -1,3 +1,3 @@
1
1
  module Slugworth
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.2.1".freeze
3
3
  end
@@ -1,11 +1,17 @@
1
1
  shared_examples_for :has_slug_functionality do
2
2
  describe "#slug" do
3
3
  context "when no slug is set" do
4
- specify 'slug is generated' do
4
+ specify 'slug is generated with slug attribute' do
5
5
  obj = described_class.new(described_class.slug_attribute => 'Generated slug')
6
6
  obj.valid?
7
7
  expect(obj.slug).to eq('generated-slug')
8
8
  end
9
+
10
+ specify 'slug is not generated with no slug attribute' do
11
+ obj = described_class.new
12
+ obj.valid?
13
+ expect(obj.slug).to be_nil
14
+ end
9
15
  end
10
16
 
11
17
  context "when the slug is set" do
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'slugworth/version'
4
+ require "slugworth/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "slugworth"
@@ -17,13 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.required_ruby_version = '>= 1.9.2'
20
+ spec.required_ruby_version = ">= 1.9.2"
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec", "~> 2.13"
25
- spec.add_development_dependency 'activerecord', '~> 4.0.0'
24
+ spec.add_development_dependency "rspec", "~> 3.3"
25
+ spec.add_development_dependency "activerecord", "~> 4.0.0"
26
26
  spec.add_development_dependency "pry"
27
- spec.add_development_dependency "database_cleaner", '~> 1.0.1'
27
+ spec.add_development_dependency "database_cleaner", "~> 1.0.1"
28
28
  spec.add_development_dependency "sqlite3"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slugworth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Polito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.13'
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.13'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.4.5
150
+ rubygems_version: 2.4.6
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Easy slug functionality