hashdown 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hashdown/select_options.rb +4 -3
- data/lib/hashdown/version.rb +1 -1
- data/spec/lib/hashdown/select_options_spec.rb +7 -1
- data/spec/support/models.rb +7 -0
- data/spec/support/schema.rb +5 -0
- data/spec/support/seeds.rb +23 -10
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 286807c97b93b855bcd7ba06d60dc1a9352e68cd
|
4
|
+
data.tar.gz: 88e736d318f67cdbd6ee00965164fd5914639720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d48a0cd467aced79339703376d64fa1d0649cb785dafcbc8e375cfa0b2121d48aed4abe0dd8b659f3cbd0c34056a32192937ec7fc53b52043ed207fcd4353e3
|
7
|
+
data.tar.gz: 1d6729c89f75f96d67e5ef41a5da3adf4b1566dc10b894e8ed3caa8bf4569b25aea64170cb7e25d8b5cdda825becde32387fda6b25c3110e16aeb0f329cfff00
|
@@ -57,9 +57,10 @@ module Hashdown
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def select_options_cache_key(options, scope)
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
Digest::MD5.hexdigest(options.sort.to_json.tap do |key|
|
61
|
+
key << scope.to_sql
|
62
|
+
key << scope.where_values_hash.to_json
|
63
|
+
end)
|
63
64
|
end
|
64
65
|
|
65
66
|
def map_records_to_select_options(records, options)
|
data/lib/hashdown/version.rb
CHANGED
@@ -47,7 +47,7 @@ describe Hashdown::SelectOptions do
|
|
47
47
|
|
48
48
|
describe 'cache layer' do
|
49
49
|
let(:states) { State.all }
|
50
|
-
let(:mock_scope) { double(arel: double(orders: %w( name )), to_sql: "SELECT * FROM states") }
|
50
|
+
let(:mock_scope) { double(arel: double(orders: %w( name )), to_sql: "SELECT * FROM states", where_values_hash: {}) }
|
51
51
|
|
52
52
|
it 'should cache found records' do
|
53
53
|
mock_scope.should_receive(:to_a).once.and_return(states)
|
@@ -73,6 +73,12 @@ describe Hashdown::SelectOptions do
|
|
73
73
|
State.starting_with_c.select_options.map(&:first).should eq %w( California Colorado )
|
74
74
|
end
|
75
75
|
|
76
|
+
it 'respects associations' do
|
77
|
+
City.starting_with_d.select_options.map(&:first).should eq %w( Dallas Denver )
|
78
|
+
State[:TX].cities.starting_with_d.select_options.map(&:first).should eq %w( Dallas )
|
79
|
+
State[:CO].cities.starting_with_d.select_options.map(&:first).should eq %w( Denver )
|
80
|
+
end
|
81
|
+
|
76
82
|
it 'clears the cache on save' do
|
77
83
|
mock_scope.should_receive(:to_a).twice.and_return(states)
|
78
84
|
State.stub(:where).and_return(mock_scope)
|
data/spec/support/models.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class State < ActiveRecord::Base
|
2
2
|
scope :starting_with_c, -> { where("name like 'C%'") }
|
3
3
|
finder :abbreviation
|
4
|
+
has_many :cities
|
4
5
|
selectable
|
5
6
|
|
6
7
|
def label
|
@@ -19,6 +20,12 @@ class StateDefaultNil < ActiveRecord::Base
|
|
19
20
|
finder :abbreviation, default: nil
|
20
21
|
end
|
21
22
|
|
23
|
+
class City < ActiveRecord::Base
|
24
|
+
scope :starting_with_d, -> { where("name like 'D%'") }
|
25
|
+
belongs_to :state
|
26
|
+
selectable
|
27
|
+
end
|
28
|
+
|
22
29
|
class Currency < ActiveRecord::Base
|
23
30
|
default_scope { order(:code) }
|
24
31
|
selectable
|
data/spec/support/schema.rb
CHANGED
data/spec/support/seeds.rb
CHANGED
@@ -10,7 +10,11 @@ class ActiveRecord::Base
|
|
10
10
|
data_table.each do |row|
|
11
11
|
data = Hash[*headers.zip(row.split(/\s*\|\s*/)[1..-1]).flatten].with_indifferent_access
|
12
12
|
if data[primary_key]
|
13
|
-
|
13
|
+
columns, values = data.each_with_object([[], []]) do |(c,v), (cols, vals)|
|
14
|
+
cols << connection.quote_column_name(c)
|
15
|
+
vals << connection.quote(v)
|
16
|
+
end
|
17
|
+
connection.execute("INSERT INTO #{table_name} (#{ columns * ', ' }) VALUES (#{ values * ', ' })")
|
14
18
|
else
|
15
19
|
create(data)
|
16
20
|
end
|
@@ -19,15 +23,24 @@ class ActiveRecord::Base
|
|
19
23
|
end
|
20
24
|
|
21
25
|
State.seed %q{
|
22
|
-
|
23
|
-
| abbreviation | name |
|
24
|
-
|
25
|
-
| AZ | Arizona |
|
26
|
-
| NY | New York |
|
27
|
-
| CA | California |
|
28
|
-
| TX | Texas |
|
29
|
-
| CO | Colorado |
|
30
|
-
|
26
|
+
+----+--------------+------------+
|
27
|
+
| id | abbreviation | name |
|
28
|
+
+----+--------------+------------+
|
29
|
+
| 1 | AZ | Arizona |
|
30
|
+
| 2 | NY | New York |
|
31
|
+
| 3 | CA | California |
|
32
|
+
| 4 | TX | Texas |
|
33
|
+
| 5 | CO | Colorado |
|
34
|
+
+----+--------------+------------+
|
35
|
+
}
|
36
|
+
|
37
|
+
City.seed %q{
|
38
|
+
+----------+------------+
|
39
|
+
| state_id | name |
|
40
|
+
+----------+------------+
|
41
|
+
| 5 | Denver |
|
42
|
+
| 4 | Dallas |
|
43
|
+
+----------+------------+
|
31
44
|
}
|
32
45
|
|
33
46
|
Currency.seed %q{
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solomon White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-19 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
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
26
|
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry-nav
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
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
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Hashdown
|
@@ -87,7 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
91
91
|
- Gemfile
|
92
92
|
- LICENSE
|
93
93
|
- README.md
|
@@ -115,17 +115,17 @@ require_paths:
|
|
115
115
|
- lib
|
116
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- -
|
118
|
+
- - ">="
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.0
|
128
|
+
rubygems_version: 2.2.0
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: super lightweight Rails plugin that adds hash-style lookups and option list
|