paraphrase 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f1f23ab1d7a4891efe1bc6159f0cc3a75b1191c
4
+ data.tar.gz: dc4755105aa6bdfbb4de5e68fe828470192c295a
5
+ SHA512:
6
+ metadata.gz: 2782d593a807d6b26fa1cb370e4874e486533bdc15a35f375ae30488306da3b3ba4e531d74d0be90d51cf777d3a02efc96ab28fb3d7c7175fe48ee4440acbe0b
7
+ data.tar.gz: 45cc94e40cd091f11c4f7b4ee48b2e96c558b95bd20dd45d53cd6beb2db09d3e8fa6eaf249c3bbc3dca321e4e59d80cbebc7bff787cd633c8623321bf861c6ef
data/Appraisals CHANGED
@@ -1,14 +1,19 @@
1
1
  appraise '3.0' do
2
- gem 'activerecord', '3.0.15'
3
- gem 'activesupport', '3.0.15'
2
+ gem 'activerecord', '~> 3.0'
3
+ gem 'activesupport', '~> 3.0'
4
4
  end
5
5
 
6
6
  appraise '3.1' do
7
- gem 'activerecord', '3.1.6'
8
- gem 'activesupport', '3.1.6'
7
+ gem 'activerecord', '~> 3.1'
8
+ gem 'activesupport', '~> 3.1'
9
9
  end
10
10
 
11
11
  appraise '3.2' do
12
- gem 'activerecord', '3.2.6'
13
- gem 'activesupport', '3.2.6'
12
+ gem 'activerecord', '~> 3.2'
13
+ gem 'activesupport', '~> 3.2'
14
+ end
15
+
16
+ appraise '4.0' do
17
+ gem 'activerecord', '~> 4.0'
18
+ gem 'activesupport', '~> 4.0'
14
19
  end
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.7.0 / 1-25-2014
2
+
3
+ * Add Rails 4 support
4
+
1
5
  0.5.0 / 8-7-2012
2
6
 
3
7
  * Cleanup ScopeMapping class
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # paraphrase
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/ecbypi/paraphrase.png)](https://codeclimate.com/github/ecbypi/paraphrase)
4
+
3
5
  Paraphrase provides a way to map request params to model scopes and apply those
4
6
  scopes based on what params are supplied. It adds a `.paraphrase` method to
5
7
  your model classes and `ActiveRecord::Relation` instances that, after setting
data/gemfiles/3.0.gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "3.0.15"
6
- gem "activemodel", "3.0.15"
7
- gem "activesupport", "3.0.15"
5
+ gem "activerecord", "~> 3.0"
6
+ gem "activesupport", "~> 3.0"
8
7
 
9
8
  gemspec :path=>"../"
@@ -1,54 +1,63 @@
1
1
  PATH
2
- remote: /Users/edd_d/src/paraphrase
2
+ remote: /Users/edd_d/Work/paraphrase
3
3
  specs:
4
4
  paraphrase (0.6.1)
5
- activerecord (~> 3.0)
6
- activesupport (~> 3.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.0.15)
12
- activesupport (= 3.0.15)
13
- builder (~> 2.1.2)
14
- i18n (~> 0.5.0)
15
- activerecord (3.0.15)
16
- activemodel (= 3.0.15)
17
- activesupport (= 3.0.15)
18
- arel (~> 2.0.10)
19
- tzinfo (~> 0.3.23)
20
- activesupport (3.0.15)
21
- appraisal (0.4.1)
11
+ activemodel (3.2.16)
12
+ activesupport (= 3.2.16)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.16)
15
+ activemodel (= 3.2.16)
16
+ activesupport (= 3.2.16)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.16)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ multi_json (~> 1.0)
22
+ appraisal (0.5.2)
22
23
  bundler
23
24
  rake
24
- arel (2.0.10)
25
- builder (2.1.2)
26
- diff-lcs (1.1.3)
27
- i18n (0.5.0)
28
- rake (0.9.2.2)
25
+ arel (3.0.3)
26
+ builder (3.0.4)
27
+ coderay (1.1.0)
28
+ diff-lcs (1.2.5)
29
+ i18n (0.6.9)
30
+ method_source (0.8.2)
31
+ multi_json (1.8.4)
32
+ pry (0.9.12.4)
33
+ coderay (~> 1.0)
34
+ method_source (~> 0.8)
35
+ slop (~> 3.4)
36
+ rake (0.9.6)
29
37
  redcarpet (2.1.1)
30
- rspec (2.10.0)
31
- rspec-core (~> 2.10.0)
32
- rspec-expectations (~> 2.10.0)
33
- rspec-mocks (~> 2.10.0)
34
- rspec-core (2.10.1)
35
- rspec-expectations (2.10.0)
36
- diff-lcs (~> 1.1.3)
37
- rspec-mocks (2.10.1)
38
- sqlite3 (1.3.6)
39
- tzinfo (0.3.33)
40
- yard (0.8.2.1)
38
+ rspec (2.14.1)
39
+ rspec-core (~> 2.14.0)
40
+ rspec-expectations (~> 2.14.0)
41
+ rspec-mocks (~> 2.14.0)
42
+ rspec-core (2.14.7)
43
+ rspec-expectations (2.14.4)
44
+ diff-lcs (>= 1.1.3, < 2.0)
45
+ rspec-mocks (2.14.4)
46
+ slop (3.4.7)
47
+ sqlite3 (1.3.8)
48
+ tzinfo (0.3.38)
49
+ yard (0.8.7.3)
41
50
 
42
51
  PLATFORMS
43
52
  ruby
44
53
 
45
54
  DEPENDENCIES
46
- activemodel (= 3.0.15)
47
- activerecord (= 3.0.15)
48
- activesupport (= 3.0.15)
55
+ activerecord (~> 3.0)
56
+ activesupport (~> 3.0)
49
57
  appraisal (~> 0.4)
50
58
  bundler (~> 1.0)
51
59
  paraphrase!
60
+ pry (~> 0.9)
52
61
  rake (~> 0.9.2)
53
62
  redcarpet (~> 2.1.1)
54
63
  rspec (~> 2.10)
data/gemfiles/3.1.gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "3.1.6"
6
- gem "activemodel", "3.1.6"
7
- gem "activesupport", "3.1.6"
5
+ gem "activerecord", "~> 3.1"
6
+ gem "activesupport", "~> 3.1"
8
7
 
9
8
  gemspec :path=>"../"
@@ -1,56 +1,63 @@
1
1
  PATH
2
- remote: /Users/edd_d/src/paraphrase
2
+ remote: /Users/edd_d/Work/paraphrase
3
3
  specs:
4
4
  paraphrase (0.6.1)
5
- activerecord (~> 3.0)
6
- activesupport (~> 3.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.1.6)
12
- activesupport (= 3.1.6)
11
+ activemodel (3.2.16)
12
+ activesupport (= 3.2.16)
13
13
  builder (~> 3.0.0)
14
- i18n (~> 0.6)
15
- activerecord (3.1.6)
16
- activemodel (= 3.1.6)
17
- activesupport (= 3.1.6)
18
- arel (~> 2.2.3)
14
+ activerecord (3.2.16)
15
+ activemodel (= 3.2.16)
16
+ activesupport (= 3.2.16)
17
+ arel (~> 3.0.2)
19
18
  tzinfo (~> 0.3.29)
20
- activesupport (3.1.6)
21
- multi_json (>= 1.0, < 1.3)
22
- appraisal (0.4.1)
19
+ activesupport (3.2.16)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ multi_json (~> 1.0)
22
+ appraisal (0.5.2)
23
23
  bundler
24
24
  rake
25
- arel (2.2.3)
26
- builder (3.0.0)
27
- diff-lcs (1.1.3)
28
- i18n (0.6.0)
29
- multi_json (1.2.0)
30
- rake (0.9.2.2)
25
+ arel (3.0.3)
26
+ builder (3.0.4)
27
+ coderay (1.1.0)
28
+ diff-lcs (1.2.5)
29
+ i18n (0.6.9)
30
+ method_source (0.8.2)
31
+ multi_json (1.8.4)
32
+ pry (0.9.12.4)
33
+ coderay (~> 1.0)
34
+ method_source (~> 0.8)
35
+ slop (~> 3.4)
36
+ rake (0.9.6)
31
37
  redcarpet (2.1.1)
32
- rspec (2.10.0)
33
- rspec-core (~> 2.10.0)
34
- rspec-expectations (~> 2.10.0)
35
- rspec-mocks (~> 2.10.0)
36
- rspec-core (2.10.1)
37
- rspec-expectations (2.10.0)
38
- diff-lcs (~> 1.1.3)
39
- rspec-mocks (2.10.1)
40
- sqlite3 (1.3.6)
41
- tzinfo (0.3.33)
42
- yard (0.8.2.1)
38
+ rspec (2.14.1)
39
+ rspec-core (~> 2.14.0)
40
+ rspec-expectations (~> 2.14.0)
41
+ rspec-mocks (~> 2.14.0)
42
+ rspec-core (2.14.7)
43
+ rspec-expectations (2.14.4)
44
+ diff-lcs (>= 1.1.3, < 2.0)
45
+ rspec-mocks (2.14.4)
46
+ slop (3.4.7)
47
+ sqlite3 (1.3.8)
48
+ tzinfo (0.3.38)
49
+ yard (0.8.7.3)
43
50
 
44
51
  PLATFORMS
45
52
  ruby
46
53
 
47
54
  DEPENDENCIES
48
- activemodel (= 3.1.6)
49
- activerecord (= 3.1.6)
50
- activesupport (= 3.1.6)
55
+ activerecord (~> 3.1)
56
+ activesupport (~> 3.1)
51
57
  appraisal (~> 0.4)
52
58
  bundler (~> 1.0)
53
59
  paraphrase!
60
+ pry (~> 0.9)
54
61
  rake (~> 0.9.2)
55
62
  redcarpet (~> 2.1.1)
56
63
  rspec (~> 2.10)
data/gemfiles/3.2.gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "3.2.6"
6
- gem "activemodel", "3.2.6"
7
- gem "activesupport", "3.2.6"
5
+ gem "activerecord", "~> 3.2"
6
+ gem "activesupport", "~> 3.2"
8
7
 
9
8
  gemspec :path=>"../"
@@ -1,56 +1,63 @@
1
1
  PATH
2
- remote: /Users/edd_d/src/paraphrase
2
+ remote: /Users/edd_d/Work/paraphrase
3
3
  specs:
4
4
  paraphrase (0.6.1)
5
- activerecord (~> 3.0)
6
- activesupport (~> 3.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.6)
12
- activesupport (= 3.2.6)
11
+ activemodel (3.2.16)
12
+ activesupport (= 3.2.16)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.6)
15
- activemodel (= 3.2.6)
16
- activesupport (= 3.2.6)
14
+ activerecord (3.2.16)
15
+ activemodel (= 3.2.16)
16
+ activesupport (= 3.2.16)
17
17
  arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.6)
20
- i18n (~> 0.6)
19
+ activesupport (3.2.16)
20
+ i18n (~> 0.6, >= 0.6.4)
21
21
  multi_json (~> 1.0)
22
- appraisal (0.4.1)
22
+ appraisal (0.5.2)
23
23
  bundler
24
24
  rake
25
- arel (3.0.2)
26
- builder (3.0.0)
27
- diff-lcs (1.1.3)
28
- i18n (0.6.0)
29
- multi_json (1.3.6)
30
- rake (0.9.2.2)
25
+ arel (3.0.3)
26
+ builder (3.0.4)
27
+ coderay (1.1.0)
28
+ diff-lcs (1.2.5)
29
+ i18n (0.6.9)
30
+ method_source (0.8.2)
31
+ multi_json (1.8.4)
32
+ pry (0.9.12.4)
33
+ coderay (~> 1.0)
34
+ method_source (~> 0.8)
35
+ slop (~> 3.4)
36
+ rake (0.9.6)
31
37
  redcarpet (2.1.1)
32
- rspec (2.10.0)
33
- rspec-core (~> 2.10.0)
34
- rspec-expectations (~> 2.10.0)
35
- rspec-mocks (~> 2.10.0)
36
- rspec-core (2.10.1)
37
- rspec-expectations (2.10.0)
38
- diff-lcs (~> 1.1.3)
39
- rspec-mocks (2.10.1)
40
- sqlite3 (1.3.6)
41
- tzinfo (0.3.33)
42
- yard (0.8.2.1)
38
+ rspec (2.14.1)
39
+ rspec-core (~> 2.14.0)
40
+ rspec-expectations (~> 2.14.0)
41
+ rspec-mocks (~> 2.14.0)
42
+ rspec-core (2.14.7)
43
+ rspec-expectations (2.14.4)
44
+ diff-lcs (>= 1.1.3, < 2.0)
45
+ rspec-mocks (2.14.4)
46
+ slop (3.4.7)
47
+ sqlite3 (1.3.8)
48
+ tzinfo (0.3.38)
49
+ yard (0.8.7.3)
43
50
 
44
51
  PLATFORMS
45
52
  ruby
46
53
 
47
54
  DEPENDENCIES
48
- activemodel (= 3.2.6)
49
- activerecord (= 3.2.6)
50
- activesupport (= 3.2.6)
55
+ activerecord (~> 3.2)
56
+ activesupport (~> 3.2)
51
57
  appraisal (~> 0.4)
52
58
  bundler (~> 1.0)
53
59
  paraphrase!
60
+ pry (~> 0.9)
54
61
  rake (~> 0.9.2)
55
62
  redcarpet (~> 2.1.1)
56
63
  rspec (~> 2.10)
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0"
6
+ gem "activesupport", "~> 4.0"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: /Users/edd_d/Work/paraphrase
3
+ specs:
4
+ paraphrase (0.6.1)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.0.2)
12
+ activesupport (= 4.0.2)
13
+ builder (~> 3.1.0)
14
+ activerecord (4.0.2)
15
+ activemodel (= 4.0.2)
16
+ activerecord-deprecated_finders (~> 1.0.2)
17
+ activesupport (= 4.0.2)
18
+ arel (~> 4.0.0)
19
+ activerecord-deprecated_finders (1.0.3)
20
+ activesupport (4.0.2)
21
+ i18n (~> 0.6, >= 0.6.4)
22
+ minitest (~> 4.2)
23
+ multi_json (~> 1.3)
24
+ thread_safe (~> 0.1)
25
+ tzinfo (~> 0.3.37)
26
+ appraisal (0.5.2)
27
+ bundler
28
+ rake
29
+ arel (4.0.1)
30
+ atomic (1.1.14)
31
+ builder (3.1.4)
32
+ coderay (1.1.0)
33
+ diff-lcs (1.2.5)
34
+ i18n (0.6.9)
35
+ method_source (0.8.2)
36
+ minitest (4.7.5)
37
+ multi_json (1.8.4)
38
+ pry (0.9.12.4)
39
+ coderay (~> 1.0)
40
+ method_source (~> 0.8)
41
+ slop (~> 3.4)
42
+ rake (0.9.6)
43
+ redcarpet (2.1.1)
44
+ rspec (2.14.1)
45
+ rspec-core (~> 2.14.0)
46
+ rspec-expectations (~> 2.14.0)
47
+ rspec-mocks (~> 2.14.0)
48
+ rspec-core (2.14.7)
49
+ rspec-expectations (2.14.4)
50
+ diff-lcs (>= 1.1.3, < 2.0)
51
+ rspec-mocks (2.14.4)
52
+ slop (3.4.7)
53
+ sqlite3 (1.3.8)
54
+ thread_safe (0.1.3)
55
+ atomic
56
+ tzinfo (0.3.38)
57
+ yard (0.8.7.3)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ activerecord (~> 4.0)
64
+ activesupport (~> 4.0)
65
+ appraisal (~> 0.4)
66
+ bundler (~> 1.0)
67
+ paraphrase!
68
+ pry (~> 0.9)
69
+ rake (~> 0.9.2)
70
+ redcarpet (~> 2.1.1)
71
+ rspec (~> 2.10)
72
+ sqlite3 (~> 1.3.6)
73
+ yard (~> 0.7)
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/object/blank'
1
2
  require 'active_support/core_ext/class/attribute'
2
3
  require 'active_support/core_ext/module/delegation'
3
4
  require 'active_support/core_ext/string/inflections'
@@ -45,10 +46,10 @@ module Paraphrase
45
46
  keys = mappings.map(&:keys).flatten.map(&:to_s)
46
47
 
47
48
  @params = HashWithIndifferentAccess.new(params)
48
- @params.select! { |key, value| keys.include?(key) }
49
+ @params.select! { |key, value| keys.include?(key) && value.present? }
49
50
  @params.freeze
50
51
 
51
- @source = class_or_relation.scoped
52
+ @source = class_or_relation
52
53
  end
53
54
 
54
55
  # Loops through {#mappings} and apply scope methods to {#source}. If values
@@ -68,8 +69,8 @@ module Paraphrase
68
69
  end
69
70
  end
70
71
 
71
- def respond_to?(name)
72
- super || results.respond_to?(name)
72
+ def respond_to_missing?(name, include_private = false)
73
+ super || results.respond_to?(name, include_private)
73
74
  end
74
75
 
75
76
  protected
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
1
3
  module Paraphrase
2
4
  class ScopeMapping
3
5
  # @!attribute [r] keys
@@ -45,7 +47,7 @@ module Paraphrase
45
47
  # @param [ActiveRecord::Relation, ActiveRecord::Base] relation scope chain
46
48
  # @return [ActiveRecord::Relation]
47
49
  def chain(params, relation)
48
- scope = relation.klass.method(method_name)
50
+ scope = relation.respond_to?(:klass) ? relation.klass.method(method_name) : relation.method(method_name)
49
51
 
50
52
  inputs = keys.map do |key|
51
53
  input = params[key]
@@ -1,3 +1,3 @@
1
1
  module Paraphrase
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
data/paraphrase.gemspec CHANGED
@@ -5,9 +5,9 @@ require File.expand_path('../lib/paraphrase/version', __FILE__)
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "paraphrase"
7
7
  gem.version = Paraphrase::VERSION
8
- gem.summary = %q{Map params to model scopes}
8
+ gem.summary = %q{Map query params to model scopes}
9
9
  gem.description = %q{
10
- Map query parameters to model scopes, pairing one or
10
+ Map query params to model scopes, pairing one or
11
11
  more keys to a scope. Parameters can be required, or
12
12
  whitelisted providing fine tuned control over how
13
13
  scopes are run.
@@ -22,8 +22,8 @@ Gem::Specification.new do |gem|
22
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
23
  gem.require_paths = ['lib']
24
24
 
25
- gem.add_dependency 'activerecord', '~> 3.0'
26
- gem.add_dependency 'activesupport', '~> 3.0'
25
+ gem.add_dependency 'activerecord', '>= 3.0', '< 4.1'
26
+ gem.add_dependency 'activesupport', '>= 3.0', '< 4.1'
27
27
 
28
28
  gem.add_development_dependency 'bundler', '~> 1.0'
29
29
  gem.add_development_dependency 'yard', '~> 0.7'
@@ -32,4 +32,5 @@ Gem::Specification.new do |gem|
32
32
  gem.add_development_dependency 'rake', '~> 0.9.2'
33
33
  gem.add_development_dependency 'sqlite3', '~> 1.3.6'
34
34
  gem.add_development_dependency 'appraisal', '~> 0.4'
35
+ gem.add_development_dependency 'pry', '~> 0.9'
35
36
  end
@@ -22,9 +22,10 @@ module Paraphrase
22
22
  let(:query) do
23
23
  klass = Class.new(Query) do
24
24
  map :name_like, :to => :name
25
+ map :email_like, :to => :email
25
26
  end
26
27
 
27
- klass.new({ :name => '', :nickname => '' }, Account)
28
+ klass.new({ :name => 'name', :nickname => '', :email => '' }, Account)
28
29
  end
29
30
 
30
31
  it "filters out params not specified in mappings" do
@@ -35,6 +36,10 @@ module Paraphrase
35
36
  it "sets up params with indifferent access" do
36
37
  query.params.should have_key 'name'
37
38
  end
39
+
40
+ it 'filters out blank values' do
41
+ query.params.should_not have_key :email
42
+ end
38
43
  end
39
44
 
40
45
  describe "#results" do
@@ -46,8 +51,8 @@ module Paraphrase
46
51
  end
47
52
 
48
53
  it "loops through scope methods and applies them to source" do
49
- Account.should_receive(:title_like).and_return(Account.scoped)
50
- Account.should_receive(:name_like).and_return(Account.scoped)
54
+ Account.should_receive(:title_like).and_return(Account)
55
+ Account.should_receive(:name_like).and_return(Account)
51
56
 
52
57
  query = klass.new({ :name => 'Jon Snow', :title => 'Wall Watcher'}, Account)
53
58
  query.results
@@ -60,24 +65,19 @@ module Paraphrase
60
65
  end
61
66
 
62
67
  describe "preserves" do
63
- let(:accounts) do
64
- user = User.create!
65
- user.accounts << Account.create!
66
- end
67
-
68
- let(:results) do
68
+ it "the relation passed in during initialization" do
69
69
  klass = Class.new(Query) do
70
70
  map :name_like, :to => :name
71
71
  end
72
72
 
73
- klass.new({ :name => 'name' }, accounts).results.to_a
74
- end
75
-
76
- it "the relation passed in during initialization" do
77
- # Create an extra account that shouldn't be in the results
73
+ user = User.create!
74
+ Account.create!(user: user)
78
75
  Account.create!
79
76
 
80
- results.should eq accounts.to_a
77
+ query = klass.new({ :name => 'name' }, Account.where(user_id: user.id))
78
+ results = query.results
79
+
80
+ results.to_a.should eq user.accounts.to_a
81
81
  end
82
82
  end
83
83
  end
@@ -6,16 +6,16 @@ module Paraphrase
6
6
  describe "#chain" do
7
7
  let(:mapping) { ScopeMapping.new(:name_like, :to => :name) }
8
8
 
9
- it "applies scope method to Account.scoped object with values from params hash" do
9
+ it "applies scope method to relation with values from params hash" do
10
10
  Account.should_receive(:name_like).with('Jon Snow')
11
11
 
12
- mapping.chain({ :name => 'Jon Snow' }, Account.scoped)
12
+ mapping.chain({ :name => 'Jon Snow' }, Account)
13
13
  end
14
14
 
15
15
  it "does nothing if values are missing" do
16
16
  Account.should_not_receive(:name_like).with('Jon Snow')
17
17
 
18
- mapping.chain({}, Account.scoped)
18
+ mapping.chain({}, Account)
19
19
  end
20
20
 
21
21
  it "passes through nil values if scope has been whitelisted" do
@@ -23,7 +23,7 @@ module Paraphrase
23
23
 
24
24
  Account.should_receive(:name_like).with(nil)
25
25
 
26
- mapping.chain({}, Account.scoped)
26
+ mapping.chain({}, Account)
27
27
  end
28
28
  end
29
29
 
@@ -35,7 +35,7 @@ module Paraphrase
35
35
  it "can require a subset of a compound key" do
36
36
  Account.should_receive(:name_like).with(nil, 'Lannister')
37
37
 
38
- compound_mapping.chain({ :last_name => 'Lannister' }, Account.scoped)
38
+ compound_mapping.chain({ :last_name => 'Lannister' }, Account)
39
39
  end
40
40
 
41
41
  it "whitelists the the non-required keys of a compound key" do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'rspec'
2
+ require 'pry'
2
3
  require 'paraphrase'
3
4
  require 'support/database'
@@ -7,16 +7,13 @@ ActiveRecord::Base.establish_connection(
7
7
  :database => ':memory:'
8
8
  )
9
9
 
10
- ActiveRecord::Base.silence do
11
- ActiveRecord::Migration.verbose = false
12
-
13
- ActiveRecord::Schema.define do
14
- create_table :users, :force => true do
15
- end
10
+ ActiveRecord::Migration.verbose = false
11
+ ActiveRecord::Schema.define do
12
+ create_table :users, :force => true do
13
+ end
16
14
 
17
- create_table :accounts, :force => true do |t|
18
- t.references :user
19
- end
15
+ create_table :accounts, :force => true do |t|
16
+ t.references :user
20
17
  end
21
18
  end
22
19
 
@@ -29,11 +26,11 @@ class Account < ActiveRecord::Base
29
26
  belongs_to :user
30
27
 
31
28
  def self.title_like(*args)
32
- scoped
29
+ ActiveRecord::VERSION::MAJOR > 3 ? all : scoped
33
30
  end
34
31
 
35
32
  def self.name_like(*args)
36
- scoped
33
+ ActiveRecord::VERSION::MAJOR > 3 ? all : scoped
37
34
  end
38
35
  end
39
36
 
metadata CHANGED
@@ -1,52 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paraphrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eduardo Gutierrez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-14 00:00:00.000000000 Z
11
+ date: 2014-01-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '4.1'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ~>
27
+ - - '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.0'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
30
33
  - !ruby/object:Gem::Dependency
31
34
  name: activesupport
32
35
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
36
  requirements:
35
- - - ~>
37
+ - - '>='
36
38
  - !ruby/object:Gem::Version
37
39
  version: '3.0'
40
+ - - <
41
+ - !ruby/object:Gem::Version
42
+ version: '4.1'
38
43
  type: :runtime
39
44
  prerelease: false
40
45
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
46
  requirements:
43
- - - ~>
47
+ - - '>='
44
48
  - !ruby/object:Gem::Version
45
49
  version: '3.0'
50
+ - - <
51
+ - !ruby/object:Gem::Version
52
+ version: '4.1'
46
53
  - !ruby/object:Gem::Dependency
47
54
  name: bundler
48
55
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
56
  requirements:
51
57
  - - ~>
52
58
  - !ruby/object:Gem::Version
@@ -54,7 +60,6 @@ dependencies:
54
60
  type: :development
55
61
  prerelease: false
56
62
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
63
  requirements:
59
64
  - - ~>
60
65
  - !ruby/object:Gem::Version
@@ -62,7 +67,6 @@ dependencies:
62
67
  - !ruby/object:Gem::Dependency
63
68
  name: yard
64
69
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
70
  requirements:
67
71
  - - ~>
68
72
  - !ruby/object:Gem::Version
@@ -70,7 +74,6 @@ dependencies:
70
74
  type: :development
71
75
  prerelease: false
72
76
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
77
  requirements:
75
78
  - - ~>
76
79
  - !ruby/object:Gem::Version
@@ -78,7 +81,6 @@ dependencies:
78
81
  - !ruby/object:Gem::Dependency
79
82
  name: rspec
80
83
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
84
  requirements:
83
85
  - - ~>
84
86
  - !ruby/object:Gem::Version
@@ -86,7 +88,6 @@ dependencies:
86
88
  type: :development
87
89
  prerelease: false
88
90
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
91
  requirements:
91
92
  - - ~>
92
93
  - !ruby/object:Gem::Version
@@ -94,7 +95,6 @@ dependencies:
94
95
  - !ruby/object:Gem::Dependency
95
96
  name: redcarpet
96
97
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
@@ -102,7 +102,6 @@ dependencies:
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
105
  requirements:
107
106
  - - ~>
108
107
  - !ruby/object:Gem::Version
@@ -110,7 +109,6 @@ dependencies:
110
109
  - !ruby/object:Gem::Dependency
111
110
  name: rake
112
111
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
112
  requirements:
115
113
  - - ~>
116
114
  - !ruby/object:Gem::Version
@@ -118,7 +116,6 @@ dependencies:
118
116
  type: :development
119
117
  prerelease: false
120
118
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
119
  requirements:
123
120
  - - ~>
124
121
  - !ruby/object:Gem::Version
@@ -126,7 +123,6 @@ dependencies:
126
123
  - !ruby/object:Gem::Dependency
127
124
  name: sqlite3
128
125
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
126
  requirements:
131
127
  - - ~>
132
128
  - !ruby/object:Gem::Version
@@ -134,7 +130,6 @@ dependencies:
134
130
  type: :development
135
131
  prerelease: false
136
132
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
133
  requirements:
139
134
  - - ~>
140
135
  - !ruby/object:Gem::Version
@@ -142,7 +137,6 @@ dependencies:
142
137
  - !ruby/object:Gem::Dependency
143
138
  name: appraisal
144
139
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
140
  requirements:
147
141
  - - ~>
148
142
  - !ruby/object:Gem::Version
@@ -150,12 +144,25 @@ dependencies:
150
144
  type: :development
151
145
  prerelease: false
152
146
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
147
  requirements:
155
148
  - - ~>
156
149
  - !ruby/object:Gem::Version
157
150
  version: '0.4'
158
- description: ! "\n Map query parameters to model scopes, pairing
151
+ - !ruby/object:Gem::Dependency
152
+ name: pry
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.9'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ~>
163
+ - !ruby/object:Gem::Version
164
+ version: '0.9'
165
+ description: "\n Map query params to model scopes, pairing
159
166
  one or\n more keys to a scope. Parameters can be required,
160
167
  or\n whitelisted providing fine tuned control over how\n
161
168
  \ scopes are run.\n "
@@ -179,6 +186,8 @@ files:
179
186
  - gemfiles/3.1.gemfile.lock
180
187
  - gemfiles/3.2.gemfile
181
188
  - gemfiles/3.2.gemfile.lock
189
+ - gemfiles/4.0.gemfile
190
+ - gemfiles/4.0.gemfile.lock
182
191
  - lib/paraphrase.rb
183
192
  - lib/paraphrase/errors.rb
184
193
  - lib/paraphrase/query.rb
@@ -195,28 +204,27 @@ files:
195
204
  homepage: https://github.com/ecbypi/paraphrase
196
205
  licenses:
197
206
  - MIT
207
+ metadata: {}
198
208
  post_install_message:
199
209
  rdoc_options: []
200
210
  require_paths:
201
211
  - lib
202
212
  required_ruby_version: !ruby/object:Gem::Requirement
203
- none: false
204
213
  requirements:
205
- - - ! '>='
214
+ - - '>='
206
215
  - !ruby/object:Gem::Version
207
216
  version: '0'
208
217
  required_rubygems_version: !ruby/object:Gem::Requirement
209
- none: false
210
218
  requirements:
211
- - - ! '>='
219
+ - - '>='
212
220
  - !ruby/object:Gem::Version
213
221
  version: '0'
214
222
  requirements: []
215
223
  rubyforge_project:
216
- rubygems_version: 1.8.23
224
+ rubygems_version: 2.0.3
217
225
  signing_key:
218
- specification_version: 3
219
- summary: Map params to model scopes
226
+ specification_version: 4
227
+ summary: Map query params to model scopes
220
228
  test_files:
221
229
  - spec/paraphrase/query_spec.rb
222
230
  - spec/paraphrase/scope_mapping_spec.rb