hashdown 0.2.3 → 0.2.4

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: b2ae3203f51852e88568edbd1e2166336e71a4c9
4
- data.tar.gz: 73912f3ce1977885a168648f412f67248b3fce19
3
+ metadata.gz: 295f9605343eb1d2b41d61440ecc6c37bc8de937
4
+ data.tar.gz: 283e18b01cad8568272ec927408c89115dedcb5e
5
5
  SHA512:
6
- metadata.gz: ba7a79495e66c86d4d4996f928d6285e3d0f52b26e242d6dcba2a84e45f7a80ca68efa9f027980468be409b71a3054d87e73e9522554d8edbb291c266847cbc3
7
- data.tar.gz: 8cfcbbfa8787db3a8bb645c52aef582f46d6170c58b54ea68a5d0950432c3d415e015bedd9cd2d0cfd347229b5dbcfaf25b478449ce68ee55248f27387b83ef7
6
+ metadata.gz: 39c65a9570f4435c0a39618a774fac0c83b94e5e28da7089f3a298422494f0b2140fbf82fc7faa2e315ad7337e1715364fc2e3955d7bd5fda4ab1e872cd30da5
7
+ data.tar.gz: b7a31edac85a0f18762e2abb0943172ad73bf83a4343a80dbab1b51e0259e6545ab26770a1b773c6be9bd90a881badc83b2b2363af41283affedf8343c7d5ec9
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ vendor/bundle
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Hashdown
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hashdown.png)](http://badge.fury.io/rb/hashdown)
4
+ [![Build Status](https://travis-ci.org/rubysolo/hashdown.png?branch=master)](https://travis-ci.org/rubysolo/hashdown)
5
+ [![Code Climate](https://codeclimate.com/github/rubysolo/hashdown.png)](https://codeclimate.com/github/rubysolo/hashdown)
6
+
3
7
  Hashdown is a super lightweight rails plugin that adds hash-style lookups and
4
8
  option lists (for generating dropdowns) to ActiveRecord models. Note: Hashdown
5
9
  has been updated to support Rails 3. If you're looking for the original plugin
data/hashdown.gemspec CHANGED
@@ -7,8 +7,9 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{Hashdown}
8
8
  gem.summary = %q{super lightweight Rails plugin that adds hash-style lookups and option list (for generating dropdowns) to ActiveRecord models}
9
9
  gem.homepage = "https://github.com/rubysolo/hashdown"
10
+ gem.license = 'MIT'
10
11
 
11
- gem.add_dependency 'activerecord', '>= 3.0'
12
+ gem.add_dependency 'activerecord', '~> 4.0'
12
13
 
13
14
  gem.add_development_dependency 'pry-nav'
14
15
  gem.add_development_dependency 'rake'
@@ -26,7 +26,7 @@ module Hashdown
26
26
  def select_options(*args)
27
27
  options = generate_options_for_cache_key(args)
28
28
 
29
- scope = scoped
29
+ scope = where(nil)
30
30
  options[:is_sorted] = scope.arel.orders.any?
31
31
  scope = select_options_scope_with_order(scope, options)
32
32
 
@@ -34,11 +34,11 @@ module Hashdown
34
34
 
35
35
  Hashdown.cached(cache_key) do
36
36
  if grouping = options[:group]
37
- scope.all.group_by {|record| grouping.call(record) }.map do |group, records|
37
+ scope.to_a.group_by { |record| grouping.call(record) }.map do |group, records|
38
38
  [group, map_records_to_select_options(records, options)]
39
39
  end
40
40
  else
41
- map_records_to_select_options(scope.all, options)
41
+ map_records_to_select_options(scope.to_a, options)
42
42
  end
43
43
  end
44
44
  end
@@ -1,3 +1,3 @@
1
1
  module Hashdown
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Hashdown do
4
4
  describe 'cache' do
5
5
  describe 'in a Rails project' do
6
- before { Object.const_set('Rails', mock(cache: :rails_cache, env: 'development')) }
6
+ before { Object.const_set('Rails', double(cache: :rails_cache, env: 'development')) }
7
7
  after { Object.send(:remove_const, 'Rails') }
8
8
 
9
9
  it 'delegates to Rails.cache if available' do
@@ -34,18 +34,18 @@ describe Hashdown::Finder do
34
34
  let(:florida) { State.new(abbreviation: 'FL', name: 'Florida') }
35
35
 
36
36
  it 'caches found records' do
37
- scope = mock(first: florida)
37
+ scope = double(first: florida)
38
38
  State.should_receive(:where).once.and_return(scope)
39
39
 
40
40
  2.times { State[:FL].name.should eq 'Florida' }
41
41
  end
42
42
 
43
43
  describe 'in test environment' do
44
- before { Object.const_set('Rails', mock(env: mock(test?: true), cache: ActiveSupport::Cache::MemoryStore.new)) }
44
+ before { Object.const_set('Rails', double(env: double(test?: true), cache: ActiveSupport::Cache::MemoryStore.new)) }
45
45
  after { Object.send(:remove_const, 'Rails') }
46
46
 
47
47
  it 'forces cache miss' do
48
- scope = mock(first: florida)
48
+ scope = double(first: florida)
49
49
  State.should_receive(:where).twice.and_return(scope)
50
50
 
51
51
  2.times { State[:FL].name.should eq 'Florida' }
@@ -53,7 +53,7 @@ describe Hashdown::Finder do
53
53
  end
54
54
 
55
55
  it 'clears the cache on save' do
56
- scope = mock(first: florida)
56
+ scope = double(first: florida)
57
57
  State.should_receive(:where).twice.and_return(scope)
58
58
 
59
59
  State[:FL].save
@@ -61,7 +61,7 @@ describe Hashdown::Finder do
61
61
  end
62
62
 
63
63
  it 'clears the cache on destroy' do
64
- scope = mock(first: florida)
64
+ scope = double(first: florida)
65
65
  State.should_receive(:where).twice.and_return(scope)
66
66
 
67
67
  State[:FL].destroy
@@ -47,22 +47,22 @@ describe Hashdown::SelectOptions do
47
47
 
48
48
  describe 'cache layer' do
49
49
  let(:states) { State.all }
50
- let(:mock_scope) { mock(arel: mock(orders: %w( name )), to_sql: "SELECT * FROM states") }
50
+ let(:mock_scope) { double(arel: double(orders: %w( name )), to_sql: "SELECT * FROM states") }
51
51
 
52
52
  it 'should cache found records' do
53
- mock_scope.should_receive(:all).once.and_return(states)
54
- State.stub(:scoped).and_return(mock_scope)
53
+ mock_scope.should_receive(:to_a).once.and_return(states)
54
+ State.stub(:where).and_return(mock_scope)
55
55
 
56
56
  2.times { State.select_options.length.should eq states.length }
57
57
  end
58
58
 
59
59
  describe 'in test environment' do
60
- before { Object.const_set('Rails', mock(env: mock(test?: true), cache: ActiveSupport::Cache::MemoryStore.new)) }
60
+ before { Object.const_set('Rails', double(env: double(test?: true), cache: ActiveSupport::Cache::MemoryStore.new)) }
61
61
  after { Object.send(:remove_const, 'Rails') }
62
62
 
63
63
  it 'forces cache miss' do
64
- mock_scope.should_receive(:all).twice.and_return(states)
65
- State.stub(:scoped).and_return(mock_scope)
64
+ mock_scope.should_receive(:to_a).twice.and_return(states)
65
+ State.stub(:where).and_return(mock_scope)
66
66
 
67
67
  2.times { State.select_options.length.should eq states.length }
68
68
  end
@@ -74,8 +74,8 @@ describe Hashdown::SelectOptions do
74
74
  end
75
75
 
76
76
  it 'clears the cache on save' do
77
- mock_scope.should_receive(:all).twice.and_return(states)
78
- State.stub(:scoped).and_return(mock_scope)
77
+ mock_scope.should_receive(:to_a).twice.and_return(states)
78
+ State.stub(:where).and_return(mock_scope)
79
79
 
80
80
  State.select_options
81
81
  states.first.save
@@ -83,8 +83,8 @@ describe Hashdown::SelectOptions do
83
83
  end
84
84
 
85
85
  it 'clears the cache on destroy' do
86
- mock_scope.should_receive(:all).twice.and_return(states)
87
- State.stub(:scoped).and_return(mock_scope)
86
+ mock_scope.should_receive(:to_a).twice.and_return(states)
87
+ State.stub(:where).and_return(mock_scope)
88
88
 
89
89
  State.select_options
90
90
  states.first.destroy
@@ -1,5 +1,5 @@
1
1
  class State < ActiveRecord::Base
2
- scope :starting_with_c, where("name like 'C%'")
2
+ scope :starting_with_c, -> { where("name like 'C%'") }
3
3
  finder :abbreviation
4
4
  selectable
5
5
 
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  class SortedState < ActiveRecord::Base
12
12
  self.table_name = 'states'
13
- default_scope order(:abbreviation)
13
+ default_scope { order(:abbreviation) }
14
14
  finder :abbreviation
15
15
  end
16
16
 
@@ -20,6 +20,6 @@ class StateDefaultNil < ActiveRecord::Base
20
20
  end
21
21
 
22
22
  class Currency < ActiveRecord::Base
23
- default_scope order(:code)
23
+ default_scope { order(:code) }
24
24
  selectable
25
25
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solomon White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-20 00:00:00.000000000 Z
11
+ date: 2013-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry-nav
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +106,8 @@ files:
106
106
  - spec/support/schema.rb
107
107
  - spec/support/seeds.rb
108
108
  homepage: https://github.com/rubysolo/hashdown
109
- licenses: []
109
+ licenses:
110
+ - MIT
110
111
  metadata: {}
111
112
  post_install_message:
112
113
  rdoc_options: []
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  requirements: []
126
127
  rubyforge_project:
127
- rubygems_version: 2.0.0
128
+ rubygems_version: 2.0.3
128
129
  signing_key:
129
130
  specification_version: 4
130
131
  summary: super lightweight Rails plugin that adds hash-style lookups and option list