acts_as_featured 0.1.2 → 0.2.0

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: b5abfb21cb04f69de8a6811788c18a486f94bcb8
4
+ data.tar.gz: 630a07ca79f5185b98262e9d56dfb097a39d403d
5
+ SHA512:
6
+ metadata.gz: c6afbf45288be429b84f87ec319992cb8062cc1c67a842ea7d13d76215f56ae8fd44858ebfb2bedde134e5a757a65ef8ed23c445ef6fd4c05d49bed0ab044be1
7
+ data.tar.gz: 61c2269947d40967273026d52cfa124d3606372a060fd6364bbe51a4f906140af65affd58f561a4461a8ca575ec0dd0366ac1b95d6b397b591585cec4e0e3d82
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
- source :rubygems
2
-
3
- gem 'rspec', '~> 2.6.0'
4
- gem 'sqlite3'
5
- gem 'sqlite3-ruby', :require => 'sqlite3'
6
- gem 'activerecord', :require => 'active_record'
1
+ source 'https://rubygems.org'
7
2
 
8
3
  gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Brandan Lennox
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown CHANGED
@@ -38,4 +38,4 @@ Make sure you run `bundle install` to get the development dependencies first.
38
38
  License
39
39
  -------
40
40
 
41
- See MIT-LICENSE.
41
+ See LICENSE.txt.
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.files = %w{
18
18
  acts_as_featured.gemspec
19
19
  Gemfile
20
- MIT-LICENSE
20
+ LICENSE.txt
21
21
  README.markdown
22
22
 
23
23
  lib/acts_as_featured.rb
@@ -32,8 +32,7 @@ Gem::Specification.new do |s|
32
32
 
33
33
  s.require_paths = ["lib"]
34
34
 
35
- s.add_dependency "activerecord", ">= 3.0.0"
36
- s.add_development_dependency "rspec"
37
- s.add_development_dependency "sqlite3"
38
- s.add_development_dependency "sqlite3-ruby"
35
+ s.add_dependency "activerecord", "~> 4.2.0"
36
+ s.add_development_dependency "rspec", "~> 3.2.0"
37
+ s.add_development_dependency "sqlite3", "~> 1.3.10"
39
38
  end
@@ -36,8 +36,8 @@ module ActsAsFeatured
36
36
  self.featured_attribute_scope = options[:scope] || false
37
37
 
38
38
  if scope_name = options[:create_scope]
39
- scope_name = attribute if scope_name === true
40
- scope scope_name, where(attribute => true).limit(1)
39
+ scope_name = attribute if scope_name == true
40
+ scope scope_name, -> { where(attribute => true).limit(1) }
41
41
  end
42
42
 
43
43
  before_save :remove_featured_from_other_records
@@ -52,15 +52,14 @@ private
52
52
  # featured, we should clear that status on other records before saving this one.
53
53
  def remove_featured_from_other_records
54
54
  if scope && send(featured_attribute)
55
- # I hope I find a better way to do this
56
- scope.update_all(["#{featured_attribute} = ?", false], "id != #{id || 0}")
55
+ scope.where.not(id: id || -1).update_all(featured_attribute => false)
57
56
  end
58
57
  end
59
58
 
60
59
  # <tt>after_save</tt> callback. If this save will result in no featured, just
61
60
  # make the first record featured.
62
61
  def add_featured_to_first_record
63
- if scope && scope.count(:conditions => { featured_attribute => true }) == 0
62
+ if scope && scope.where(featured_attribute => true).none?
64
63
  scope.first.update_attribute(featured_attribute, true)
65
64
  end
66
65
  end
@@ -68,9 +67,9 @@ private
68
67
  # <tt>before_destroy</tt> callback. If we destroy the featured, make the first
69
68
  # unfeaturedmain the featured. If this was the last record, don't do anything.
70
69
  def add_featured_to_first_record_if_featured
71
- if scope && send(featured_attribute) && scope.count > 1
72
- new_main = scope.find(:first, :conditions => { featured_attribute => false })
73
- new_main.update_attribute(featured_attribute, true) unless new_main.nil?
70
+ if scope && send(featured_attribute) && scope.many?
71
+ new_main = scope.where(featured_attribute => false).first
72
+ new_main.update(featured_attribute => true) if new_main
74
73
  end
75
74
  end
76
75
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsFeatured
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe ActsAsFeatured do
3
+ RSpec.describe ActsAsFeatured do
4
4
  def featured(model)
5
- model.find_all_by_featured(true)
5
+ model.where(featured: true)
6
6
  end
7
7
 
8
8
  describe "unscoped" do
@@ -16,9 +16,9 @@ describe ActsAsFeatured do
16
16
 
17
17
  it 'should leave featured status alone when saving the currently featured thingy' do
18
18
  originally_featured = Thingy.create(:featured => true)
19
- featured(Thingy).first.should == originally_featured
19
+ expect(featured(Thingy).first).to eq(originally_featured)
20
20
  originally_featured.save
21
- featured(Thingy).first.should == originally_featured
21
+ expect(featured(Thingy).first).to eq(originally_featured)
22
22
  end
23
23
 
24
24
  it 'should remove featured status from the currently featured thingy when setting it on another thingy' do
@@ -31,9 +31,9 @@ describe ActsAsFeatured do
31
31
  originally_featured.reload
32
32
  will_be_featured.reload
33
33
 
34
- featured(Thingy).should have(1).item
35
- originally_featured.featured?.should be_false
36
- will_be_featured.featured?.should be_true
34
+ expect(featured(Thingy).count).to eq(1)
35
+ expect(originally_featured).not_to be_featured
36
+ expect(will_be_featured).to be_featured
37
37
  end
38
38
 
39
39
  it 'should set another thingy to be featured when removing featured status from the featured thingy' do
@@ -44,8 +44,8 @@ describe ActsAsFeatured do
44
44
  originally_featured.save!
45
45
  originally_featured.reload
46
46
 
47
- featured(Thingy).should have(1).item
48
- originally_featured.featured?.should be_false
47
+ expect(featured(Thingy).count).to eq(1)
48
+ expect(originally_featured).not_to be_featured
49
49
  end
50
50
 
51
51
  it 'should set another thingy to be featured when destroying the featured thingy' do
@@ -54,7 +54,7 @@ describe ActsAsFeatured do
54
54
 
55
55
  originally_featured.destroy
56
56
 
57
- featured(Thingy).should have(1).item
57
+ expect(featured(Thingy).count).to eq(1)
58
58
  end
59
59
  end
60
60
 
@@ -73,35 +73,35 @@ describe ActsAsFeatured do
73
73
  f1 = aggregator1.scoped_thingies.create(:featured => true)
74
74
  f2 = aggregator2.scoped_thingies.create(:featured => true)
75
75
 
76
- featured(ScopedThingy).should have(2).items
76
+ expect(featured(ScopedThingy).count).to eq(2)
77
77
 
78
- f1.update_attribute(:featured, false)
78
+ f1.update_attributes(:featured => false)
79
79
 
80
- featured(ScopedThingy).should have(2).items
81
- aggregator2.scoped_thingies.find_by_featured(true).should == f2
80
+ expect(featured(ScopedThingy).count).to eq(2)
81
+ expect(aggregator2.scoped_thingies.find_by_featured(true)).to eq(f2)
82
82
  end
83
83
 
84
84
  it 'should not explode when the scope is nil' do
85
85
  expect {
86
86
  ScopedThingy.create!(:featured => true)
87
- featured(ScopedThingy).should have(1).item
87
+ expect(featured(ScopedThingy).count).to eq(1)
88
88
  }.not_to raise_error
89
89
  end
90
90
  end
91
91
 
92
92
  describe "named scope" do
93
93
  it 'should add a default named scope' do
94
- DefaultNamedScopeThingy.should respond_to(:featured)
94
+ expect(DefaultNamedScopeThingy).to respond_to(:featured)
95
95
  end
96
96
 
97
97
  it 'should add a custom named scope' do
98
- CustomNamedScopeThingy.should respond_to(:special)
98
+ expect(CustomNamedScopeThingy).to respond_to(:special)
99
99
  end
100
100
 
101
101
  it 'should return the featured thingy from the named scope' do
102
102
  3.times { DefaultNamedScopeThingy.create!(:featured => false) }
103
103
  t = DefaultNamedScopeThingy.create!(:featured => true)
104
- DefaultNamedScopeThingy.featured.first.should == t
104
+ expect(DefaultNamedScopeThingy.featured.first).to eq(t)
105
105
  end
106
106
  end
107
107
  end
data/spec/models.rb CHANGED
@@ -33,7 +33,7 @@ ActiveRecord::Schema.define(:version => 1) do
33
33
  end
34
34
 
35
35
  create_table :thingy_aggregators, :force => true do |t|
36
- t.timestamps
36
+ t.timestamps null: false
37
37
  end
38
38
 
39
39
  create_table :scoped_thingies, :force => true do |t|
metadata CHANGED
@@ -1,94 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: acts_as_featured
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Brandan Lennox
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-01-28 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2012-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: activerecord
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- - 0
33
- version: 3.0.0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
34
20
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
21
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
48
34
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: sqlite3
52
35
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.10
62
48
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: sqlite3-ruby
66
49
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
68
- none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- type: :development
77
- version_requirements: *id004
78
- description: Designates an attribute on this model to indicate "featuredness," where only one record within a given scope may be featured at a time.
79
- email:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.10
55
+ description: Designates an attribute on this model to indicate "featuredness," where
56
+ only one record within a given scope may be featured at a time.
57
+ email:
80
58
  - brandan@bclennox.com
81
59
  executables: []
82
-
83
60
  extensions: []
84
-
85
61
  extra_rdoc_files: []
86
-
87
- files:
88
- - acts_as_featured.gemspec
62
+ files:
89
63
  - Gemfile
90
- - MIT-LICENSE
64
+ - LICENSE.txt
91
65
  - README.markdown
66
+ - acts_as_featured.gemspec
92
67
  - lib/acts_as_featured.rb
93
68
  - lib/acts_as_featured/version.rb
94
69
  - spec/acts_as_featured_spec.rb
@@ -96,38 +71,28 @@ files:
96
71
  - spec/spec_helper.rb
97
72
  homepage: https://github.com/bclennox/acts_as_featured
98
73
  licenses: []
99
-
74
+ metadata: {}
100
75
  post_install_message:
101
76
  rdoc_options: []
102
-
103
- require_paths:
77
+ require_paths:
104
78
  - lib
105
- required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
108
81
  - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
114
- required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
117
86
  - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
123
89
  requirements: []
124
-
125
90
  rubyforge_project: acts_as_featured
126
- rubygems_version: 1.8.15
91
+ rubygems_version: 2.4.2
127
92
  signing_key:
128
- specification_version: 3
93
+ specification_version: 4
129
94
  summary: Designate a Rails model attribute as unique within a scope
130
- test_files:
95
+ test_files:
131
96
  - spec/acts_as_featured_spec.rb
132
97
  - spec/models.rb
133
98
  - spec/spec_helper.rb
data/MIT-LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2009 Brandan Lennox
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.