slugworth 1.0.2 → 1.1.0

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: 72bc1085707d9ccfb3438869fe15c2052d9b9512
4
- data.tar.gz: 25f6d11385d7cc75e02fb1fc539e3bcea4ee3dc9
3
+ metadata.gz: 580a1a33372ba7781fca6dae4df6e8ac523e8dfd
4
+ data.tar.gz: 4d8c73c9c421d5ae254bc5759e4617554e582f03
5
5
  SHA512:
6
- metadata.gz: a3ad7d1f90683c938bcd897ce92cb7f1ed2769f801ff51898b8e811a2a03cebbcd3ae0e9501199906cbf1f112b5982952358d764cef5dfb43e7af1540eaa3c97
7
- data.tar.gz: ad736a6ae681cbf4a534abb21828fc3be99d6ea3165d8cbce994ad8d81f5801c5bf3af8bc5dc29f8baf837dbe192ab0c3068d70c8e9f1c36005cf87a5ded1aa2
6
+ metadata.gz: f24f96d281279619fcbd20cb8ef0509c4f38477f0b4c1ca8c9ce3616e63ab3d049c6158f2a01e11b35ca2dd5381ac507fd3d9492bb97ed6fdc4e451316dc2483
7
+ data.tar.gz: a844d24078f0684af671ba5941ce92173d3bbd4bafae7b54db25178f18cb50fa933f60416bcca06f37b8d290201b9f6322226fa1e8b2b7e2d124f7690e6ddd19
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - `#find_by_slug` has been changed to `#find_by_slug` to keep in line with AR
6
+ finder syntax
7
+
3
8
  ## 1.0.2
4
9
 
5
10
  - [Bug fix] Bypassing validations for `#find_by_slug` spec in shared example.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Slugworth
1
+ ![Slugworth](http://f.cl.ly/items/3T1K3g040S0u2l0G0d3V/slugworth_header.png)
2
2
 
3
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/sluggle)
5
- [![Code Climate](https://codeclimate.com/github/mattpolito/slugworth.png)](https://codeclimate.com/github/mattpolito/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)
6
6
 
7
7
  Simple slug functionality for your ActiveRecord objects
8
8
 
@@ -32,7 +32,7 @@ install it yourself with
32
32
 
33
33
  Getting started is easy! Just ensure that your model has a database column of type `String` called `slug`
34
34
 
35
- To use just add two declarations to your module and away you go!
35
+ To use, just add two declarations to your `ActiveRecord` class and away you go!
36
36
 
37
37
  ```ruby
38
38
  class User < ActiveRecord::Base
@@ -41,11 +41,29 @@ 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.
45
+
44
46
  This provides most of the default slug functionality you would need.
45
47
 
46
- * A finder `.find_by_slug` is provided. This will, of course, do what you expect and find a single record by the slug attribute provided. However, it will throw an `ActiveRecord::RecordNotFound` exception... if not found.
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.
47
49
  * `#to_param` has been defined as a paramaterized version of the attribute declared to `slugged_with`.
48
- * Validations stating that slug is present and unique in the database.
50
+ * Validations stating that `slug` is present and unique in the database.
51
+
52
+ ## Test Helper
53
+
54
+ To aid in testing your models that implement the Slugworth functionality, I've added a shared example group that can be added to your test suite. Add this to your `spec_helper.rb`
55
+
56
+ ```ruby
57
+ include 'slugworth_shared_examples'
58
+ ```
59
+
60
+ And then in your specs just add:
61
+
62
+ ```ruby
63
+ it_behaves_like :has_slug_functionality
64
+ ```
65
+
66
+ This will add the same specs to your model that get run on Slugworth itself!
49
67
 
50
68
  ## Contributing
51
69
 
@@ -54,3 +72,9 @@ This provides most of the default slug functionality you would need.
54
72
  3. Commit your changes (`git commit -am 'Add some feature'`)
55
73
  4. Push to the branch (`git push origin my-new-feature`)
56
74
  5. Create new Pull Request
75
+
76
+ ## Thanks
77
+
78
+ * [Rye Mason][] for the fantastic heading image.
79
+
80
+ [Rye Mason]: https://github.com/ryenotbread
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/slugworth.rb CHANGED
@@ -14,9 +14,13 @@ module Slugworth
14
14
  self.slug_attribute = slug_attribute
15
15
  end
16
16
 
17
- def find_by_slug(slug)
17
+ def find_by_slug!(slug)
18
18
  find_by!(slug: slug)
19
19
  end
20
+
21
+ def find_by_slug(slug)
22
+ find_by(slug: slug)
23
+ end
20
24
  end
21
25
 
22
26
  def to_param; slug; end
@@ -27,6 +31,6 @@ module Slugworth
27
31
  end
28
32
 
29
33
  def processed_slug
30
- send(slug_attribute).parameterize
34
+ public_send(slug_attribute).parameterize
31
35
  end
32
36
  end
@@ -1,3 +1,3 @@
1
1
  module Slugworth
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0".freeze
3
3
  end
@@ -51,8 +51,12 @@ shared_examples_for :has_slug_functionality do
51
51
  end
52
52
 
53
53
  context 'when record is not found' do
54
- specify 'error is returned' do
55
- expect { described_class.find_by_slug('named-slug') }.to raise_error(ActiveRecord::RecordNotFound)
54
+ specify 'nil is returned' do
55
+ expect(described_class.find_by_slug('named-slug')).to eq(nil)
56
+ end
57
+
58
+ specify 'error is raised' do
59
+ expect{ described_class.find_by_slug!('named-slug') }.to raise_error(ActiveRecord::RecordNotFound)
56
60
  end
57
61
  end
58
62
  end
data/slugworth.gemspec CHANGED
@@ -14,15 +14,16 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
20
+ spec.required_ruby_version = '>= 1.9.2'
21
+
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
  spec.add_development_dependency "rake"
23
24
  spec.add_development_dependency "rspec", "~> 2.13"
24
25
  spec.add_development_dependency 'activerecord', '~> 4.0.0'
25
26
  spec.add_development_dependency "pry"
26
- spec.add_development_dependency "database_cleaner"
27
+ spec.add_development_dependency "database_cleaner", '~> 1.0.1'
27
28
  spec.add_development_dependency "sqlite3"
28
29
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'rspec'
2
2
  require 'database_cleaner'
3
-
4
- require 'active_support/concern'
5
3
  require 'active_record'
6
4
 
7
5
  ActiveRecord::Base.establish_connection(
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.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Polito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-01 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: database_cleaner
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.0.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 1.0.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -116,9 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - .gitignore
119
- - .ruby-gemset
120
- - .ruby-version
121
- - CHANGELOG
119
+ - CHANGELOG.md
122
120
  - Gemfile
123
121
  - LICENSE.txt
124
122
  - README.md
@@ -141,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
139
  requirements:
142
140
  - - '>='
143
141
  - !ruby/object:Gem::Version
144
- version: '0'
142
+ version: 1.9.2
145
143
  required_rubygems_version: !ruby/object:Gem::Requirement
146
144
  requirements:
147
145
  - - '>='
@@ -149,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
147
  version: '0'
150
148
  requirements: []
151
149
  rubyforge_project:
152
- rubygems_version: 2.0.3
150
+ rubygems_version: 2.0.6
153
151
  signing_key:
154
152
  specification_version: 4
155
153
  summary: Easy slug functionality
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- slugworth
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0