filterrific 1.3.1 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d44cdb5ab999e5e889376c0d0eb35f1964f13b82
4
- data.tar.gz: b48205b853f675acc7c4013f211f5b67333e231d
3
+ metadata.gz: cfeeb89ecbb8633a86e9714443be0e1dec39b28b
4
+ data.tar.gz: 29795af6901eab99af4dcdd8009defb4fb3295fb
5
5
  SHA512:
6
- metadata.gz: 858c6cb75d9f41facd855fb8a41c9ebce9dbdf737f4e76a370588c819ebd9336727cab61d67751a79750a8b08b27f10fffe19825689ab991ea6d87381bd7dd69
7
- data.tar.gz: e78690c520dc35c8e89e533cbcbf135e3a031487331078f6d98255a17deb14fbf25c86d44fe89ec6d864536f0cc78e8e18c6970d341cae0db8b0d11409673c5c
6
+ metadata.gz: 1162e9fb2f9f4338355d0467d5c014968fe1f7599bc9144eeede2f3b497eb6f5a9d60f1d1104c615bbaf56bfcac1493aac09a7a8049fd15e437c2e04e054ac29
7
+ data.tar.gz: 26b93548f73deaf22da434d237e1b4adea446abb2ece75bc68c2ee57cbd8e3440f381a4e1f4f7cf16948a725b7125ae9fc07f7ae02b9f8358272fb137eaf8a2d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,63 @@
1
+ # 2.0.0
2
+
3
+ API changes
4
+
5
+ * Filterrific can build the `sorted_by` and `search_query` scopes automatically,
6
+ based on some configuration in the including model.
7
+
8
+ filterrific(
9
+ default_settings: { sorted_by: 'name_asc' },
10
+ search_query: {
11
+ match: :any
12
+ wildcard: :suffix,
13
+ adaptor: :postgres
14
+ },
15
+ sorted_by: {
16
+ name_asc: 'Name (A-Z)',
17
+ name_desc: 'Name (Z-A)'
18
+ },
19
+ filter_names: [
20
+ :with_country,
21
+ ...
22
+ ]
23
+ )
24
+
25
+ * Filterrific can handle persistence of search params in session for you.
26
+ * Simplified `@filterrific.find` method to load collection from DB.
27
+ Replaces `Student.filterrific_find(@filterrific)`
28
+
29
+ @filterrific = initialize_filterrific(
30
+ Student,
31
+ default_settings: {},
32
+ filter_names: [],
33
+ params_key: :filterrific,
34
+ select_options: {},
35
+ session_persistence: 'asdf',
36
+ )
37
+ @students = @filterrific.find
38
+
39
+ * The filterrific form builder now doesn't override the standard
40
+ `form_for` method. It is used via `form_for_filterrific` instead:
41
+
42
+ form_for_filterrific @filterrific do |f|
43
+
44
+ * Dropped support for Ruby 1.8.7 (because of 1.9 Hash syntax)
45
+ * Dropped support for Rails <= 3.0.0 (because of ActiveRecord
46
+ bug fixes in 3.1, and use of asset pipeline)
47
+
48
+
49
+
50
+ ### 1.4.0
51
+
52
+ * Better support for new versions of Rails (integration tests are done in filterrific_demo)
53
+ * Fixed asset pipeline for filterrific-spinner.gif.
54
+ * Isolate_namespace
55
+ * Update Gem dependencies
56
+ * Switch from Rspec to Minitest
57
+ * Require Rails 3.1 or greater
58
+
59
+
60
+
1
61
  ### 1.3.1
2
62
 
3
63
  * Changed ParamSet#select_options so that a complete hash can be assigned
@@ -32,7 +92,6 @@
32
92
 
33
93
 
34
94
 
35
-
36
95
  ## 1.1.0
37
96
 
38
97
  * Major refactor.
@@ -41,13 +100,13 @@
41
100
  * Added gh-pages branch for documentation.
42
101
 
43
102
 
103
+
44
104
  ### 1.0.1
45
105
 
46
106
  * Bug fix: Replaced stringify_keys with map.to_s (filter_names is an Array, not a Hash!).
47
107
 
48
108
 
49
109
 
50
-
51
110
  # 1.0.0
52
111
 
53
112
  * Support for Rails 3.1.
@@ -60,6 +119,7 @@
60
119
  * Replicate functionality of Rails 2.3 version.
61
120
 
62
121
 
122
+
63
123
  ### 0.0.1, released 2010-07-30
64
124
 
65
125
  * Initial setup.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Jo Hund
1
+ Copyright (c) 2010-2014 Jo Hund
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -7,7 +7,7 @@ searching, and sorting to your ActiveRecord lists.
7
7
  Make sure to go to the fantastic [Filterrific documentation](http://filterrific.clearcove.ca)
8
8
  to find out more!
9
9
 
10
-
10
+ TODO: look at Jeff's email suggestions (June 23, 2014)
11
11
 
12
12
  ### Installation
13
13
 
@@ -18,6 +18,18 @@ or with bundler in your Gemfile:
18
18
  `gem 'filterrific'`
19
19
 
20
20
 
21
+ ### Guidelines for submitting issues
22
+
23
+ I'm happy to help you if you encounter problems when using filterrific. You'll make my job easier if you follow these guidelines:
24
+
25
+ * Please keep in mind that I do this in my spare time. I appreciate it if you first do everything you can on your own: read the detailed filterrific documentation, look for similar issues on StackOverflow, search the internets, etc.
26
+ * If you're stuck, give me sufficient context so that I have a chance to identify the issue:
27
+ * what version of filterrific are you using? (look in your `Gemfile.lock`)
28
+ * what version of Rails are you using? (look in your `Gemfile.lock`)
29
+ * what version of Ruby are you using? (run `ruby -v` in your app root)
30
+ * If you get an exception, include the entire stack trace, including the error message.
31
+ * Include any relevant code snippets (your model, controller, and view code).
32
+
21
33
 
22
34
  ### Resources
23
35
 
@@ -28,6 +40,8 @@ or with bundler in your Gemfile:
28
40
  * [Issues](https://github.com/jhund/filterrific/issues)
29
41
  * [Rubygems.org](http://rubygems.org/gems/filterrific)
30
42
 
43
+ [![Build Status](https://travis-ci.org/jhund/filterrific.svg?branch=master)](https://travis-ci.org/jhund/filterrific)
44
+
31
45
  [![Code Climate](https://codeclimate.com/github/jhund/filterrific.png)](https://codeclimate.com/github/jhund/filterrific)
32
46
 
33
47
  ### License
@@ -38,4 +52,4 @@ or with bundler in your Gemfile:
38
52
 
39
53
  ### Copyright
40
54
 
41
- Copyright (c) 2010 - 2013 Jo Hund. See [(MIT) LICENSE](https://github.com/jhund/filterrific/blob/master/MIT-LICENSE) for details.
55
+ Copyright (c) 2010 - 2014 Jo Hund. See [(MIT) LICENSE](https://github.com/jhund/filterrific/blob/master/MIT-LICENSE) for details.
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
- # encoding: utf-8
2
-
3
1
  begin
4
- require 'bundler'
2
+ require 'bundler/setup'
5
3
  rescue LoadError
6
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
5
  end
8
- Bundler::GemHelper.install_tasks
9
6
 
10
- require 'rspec/core'
11
- require 'rspec/core/rake_task'
7
+ Bundler::GemHelper.install_tasks
12
8
 
13
- RSpec::Core::RakeTask.new(:spec) do |spec|
14
- spec.pattern = FileList['spec/**/*_spec.rb']
9
+ require 'rake/testtask'
10
+ Rake::TestTask.new do |test|
11
+ test.libs << 'spec'
12
+ test.pattern = 'spec/**/*_spec.rb'
13
+ test.verbose = true
15
14
  end
16
15
 
17
- task :default => :spec
16
+ require 'wwtd/tasks'
17
+ task default: 'wwtd:local'
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/filterrific/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
data/doc/meta.md CHANGED
@@ -32,3 +32,14 @@ How to run specs
32
32
  ----------------
33
33
 
34
34
  `bundle exec rake`
35
+
36
+
37
+ Travis CI
38
+ ---------
39
+
40
+ filterrific uses Travis CI for testing. Currently we test the following ruby
41
+ versions:
42
+
43
+ * 1.9.3
44
+ * 2.0.0
45
+ * 2.1.1
data/doc/scratchpad.md ADDED
@@ -0,0 +1,58 @@
1
+ # Filterrific scratchpad
2
+
3
+ ## TODO
4
+
5
+ * add check that no filter_name conflicts with existing methods on included ActiveRecord class (See https://github.com/jhund/filterrific/issues/17)
6
+
7
+ ## Travis
8
+
9
+ Example setups:
10
+
11
+ * https://github.com/mislav/will_paginate/blob/master/.travis.yml
12
+ * https://github.com/stripe/stripe-ruby/blob/master/.travis.yml
13
+
14
+ Filterrific 2
15
+
16
+ * requires Ruby 1.9.3 or later
17
+ * requires Rails 3.1 or later
18
+ * new syntax
19
+ * better test coverage
20
+
21
+ test matrix
22
+
23
+ Rails 2.x Rails 3.0 Rails 3.1 Rails 3.2 Rails 4.0 Rails 4.1 Rails Edge
24
+ Ruby 1.8.7
25
+ Ruby 1.9.3
26
+ Ruby 2.0
27
+ Ruby 2.1
28
+
29
+ Each combination is also tested for postgres and mysql
30
+
31
+ wwtd to simulate travis
32
+
33
+ plataformatec/devise uses the rails stable branch from git.
34
+ That's an interesting idea.
35
+
36
+ ## Options for proper test matrix
37
+
38
+ * appraisal by thoughtbot -1
39
+ * wwtd: ++ for being able to run tests locally
40
+ * ENV vars (steve klabnik's approach)
41
+ * use combustion gem for testing without dummy app? nah. It doesn't support Rails 4
42
+
43
+ Preferred method:
44
+
45
+ * use ENV vars in travis.yml for Rails versions
46
+ * use steve klabnik's approach for selecting the correct gemfile
47
+ * use ENV vars to choose correct dummy app
48
+
49
+ Apps to generate dummy apps for each version:
50
+
51
+ bundle exec rails plugin new ~/development/filterrific_4.1/filterrific -T --mountable --dummy-path=spec/dummy --database=postgresql
52
+
53
+ [differences between full and mountable engine](http://stackoverflow.com/a/17263429)
54
+
55
+ * 3.1: ibo-pts
56
+ * 3.2: filterrific_demo (sqlite3)
57
+ * 4.0: yikesite (mysql)
58
+ * 4.1: utilibase (postgresql)
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  #
2
4
  # Adds view helpers to ActionView
3
5
  #
@@ -14,14 +16,95 @@ module Filterrific::ActionViewExtension
14
16
  end
15
17
  super
16
18
  end
19
+ # TODO: change this to form_for_filterrific!
17
20
 
18
21
  # Renders a spinner while the list is being updated
19
22
  def render_filterrific_spinner
20
23
  %(
21
24
  <span class="filterrific_spinner" style="display:none;">
22
- #{ image_tag('filterrific-spinner.gif') }
25
+ #{ image_tag('filterrific/filterrific-spinner.gif') }
23
26
  </span>
24
27
  ).html_safe
25
28
  end
29
+ #alias: filterrific_spinner
30
+
31
+ # Renders a link which indicates the current sorting and which can be used to
32
+ # toggle the list sorting (set column and direction).
33
+ # NOTE: Make sure that this is used in the list partial that is re-rendered
34
+ # when the filterrific params are changed, so that the filterrific params in
35
+ # the URL are always current.
36
+ # @param[Filterrific::ParamSet] filterrific the current filterrific instance
37
+ # @param[String, Symbol] sort_key the key to sort by, without direction.
38
+ # Example: 'name', 'created_at'
39
+ # @param[Hash, optional] options:
40
+ # * active_column_class: CSS class applied to current sort column.
41
+ # Default: 'filterrific_current_sort_column'
42
+ # * ascending_indicator: HTML string to indicate ascending sort direction.
43
+ # Default: Triangle pointing up.
44
+ # * default_sort_direction: override the default sorting when selecting
45
+ # a new sort column. Default: 'asc'.
46
+ # * descending_indicator: HTML string to indicate descending sort direction.
47
+ # Default: Triangle pointing down.
48
+ # * html_attrs: HTML attributes to be added to the sorting link. Default: {}
49
+ # * label: override label. Default: `sort_key.humanize`.
50
+ # * sorting_scope_name: override the name of the scope used for sorting.
51
+ # Default: `:sorted_by`
52
+ # * url_for_attrs: override the target URL attributes to be used for `url_for`.
53
+ # Default: {} (current URL).
54
+ # TODO: update documentation
55
+ # TODO: update demo app
56
+ # TODO: synchronize with sorting select in filter
57
+ def filterrific_sorting_link(filterrific, sort_key, options = {})
58
+ options = {
59
+ :active_column_class => 'filterrific_current_sort_column',
60
+ :ascending_indicator => '⬆',
61
+ :default_sort_direction => 'asc',
62
+ :descending_indicator => '⬇',
63
+ :html_attrs => {},
64
+ :label => sort_key.to_s.humanize,
65
+ :sorting_scope_name => :sorted_by,
66
+ :url_for_attrs => {},
67
+ }.merge(options)
68
+ options[:html_attrs] = options[:html_attrs].with_indifferent_access
69
+ current_sorting = filterrific.send(options[:sorting_scope_name])
70
+ current_sort_key = current_sorting ? current_sorting.gsub(/_asc|_desc/, '') : nil
71
+ current_sort_direction = current_sorting ? (current_sorting =~ /_desc\z/ ? 'desc' : 'asc') : nil
72
+ new_sort_key = sort_key.to_s
73
+ if new_sort_key == current_sort_key
74
+ # current sort column, toggle search_direction
75
+ new_sort_direction, current_sort_direction_indicator = if 'asc' == current_sort_direction
76
+ ['desc', options[:ascending_indicator]]
77
+ else
78
+ ['asc', options[:descending_indicator]]
79
+ end
80
+ new_sorting = [new_sort_key, new_sort_direction].join('_')
81
+ css_classes = [
82
+ options[:active_column_class],
83
+ options[:html_attrs].delete(:class)
84
+ ].compact.join(' ')
85
+ new_filterrific_params = filterrific.to_hash
86
+ .with_indifferent_access
87
+ .merge(options[:sorting_scope_name] => new_sorting)
88
+ url_for_attrs = options[:url_for_attrs].merge(:filterrific => new_filterrific_params)
89
+ link_to(
90
+ [options[:label], current_sort_direction_indicator].join(' '),
91
+ url_for(url_for_attrs),
92
+ options[:html_attrs].reverse_merge(:class => css_classes, :method => :get, :remote => true)
93
+ )
94
+ else
95
+ # new sort column, change sort column
96
+ new_sort_direction = options[:default_sort_direction]
97
+ new_sorting = [new_sort_key, new_sort_direction].join('_')
98
+ new_filterrific_params = filterrific.to_hash
99
+ .with_indifferent_access
100
+ .merge(options[:sorting_scope_name] => new_sorting)
101
+ url_for_attrs = options[:url_for_attrs].merge(:filterrific => new_filterrific_params)
102
+ link_to(
103
+ options[:label],
104
+ url_for(url_for_attrs),
105
+ options[:html_attrs].reverse_merge(:method => :get, :remote => true)
106
+ )
107
+ end
108
+ end
26
109
 
27
110
  end
@@ -1,11 +1,11 @@
1
- require 'rails'
2
-
3
1
  module Filterrific
4
2
  class Engine < ::Rails::Engine
5
3
 
6
4
  # It's an engine so that we can add javascript and image assets
7
5
  # to the asset pipeline.
8
6
 
7
+ isolate_namespace Filterrific
8
+
9
9
  require 'filterrific/param_set'
10
10
 
11
11
  initializer "filterrific.active_record_extension" do |app|
@@ -22,5 +22,9 @@ module Filterrific
22
22
  end
23
23
  end
24
24
 
25
+ initializer "filterrific.assets.precompile" do |app|
26
+ app.config.assets.precompile += %w(filterrific-spinner.gif)
27
+ end
28
+
25
29
  end
26
30
  end
@@ -25,6 +25,12 @@ module Filterrific
25
25
  define_attr_accessors_for_each_filter(filterrific_params)
26
26
  end
27
27
 
28
+ # A shortcut to run the ActiveRecord query on resource_class. Use this if
29
+ # you want to start with the resource_class, and not a special ActiveRecord::Relation.
30
+ def find
31
+ resource_class.filterrific_find(self)
32
+ end
33
+
28
34
  # Returns Filterrific::ParamSet as hash (used for URL params and serialization)
29
35
  def to_hash
30
36
  {}.tap { |h|
@@ -1,3 +1,3 @@
1
1
  module Filterrific
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'filterrific/action_view_extension'
3
+
4
+ module Filterrific
5
+
6
+ class ViewContext
7
+ include ActionViewExtension
8
+ end
9
+
10
+ describe ActionViewExtension do
11
+
12
+ describe '#render_filterrific_spinner' do
13
+ it "renders filterrific spinner" do
14
+ ViewContext.new.must_respond_to(:render_filterrific_spinner)
15
+ end
16
+ end
17
+
18
+ describe '#filterrific_sorting_link' do
19
+ it 'changes sorting on new column' do
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'active_record'
3
+ require 'filterrific/active_record_extension'
4
+
5
+ ActiveRecord::Base.extend Filterrific::ActiveRecordExtension::ClassMethods
6
+
7
+ module Filterrific
8
+
9
+ # Container for test data
10
+ class TestData
11
+
12
+ def self.filterrific_filter_names
13
+ %w[sorted_by search_query with_country_id]
14
+ end
15
+
16
+ def self.filterrific_default_settings
17
+ { 'sorted_by' => 'name_asc' }
18
+ end
19
+
20
+ end
21
+
22
+ describe ActiveRecordExtension do
23
+
24
+ let(:filterrific_class){
25
+ Class.new(ActiveRecord::Base) do
26
+ filterrific(
27
+ :filter_names => TestData.filterrific_filter_names,
28
+ :default_settings => TestData.filterrific_default_settings
29
+ )
30
+ end
31
+ }
32
+
33
+ describe "Class method extensions" do
34
+
35
+ it "adds a 'filterrific' class method" do
36
+ filterrific_class.must_respond_to(:filterrific)
37
+ end
38
+
39
+ it "adds a 'filterrific_find' class method" do
40
+ filterrific_class.must_respond_to(:filterrific_find)
41
+ end
42
+
43
+ end
44
+
45
+ describe "Filterrific initialization" do
46
+
47
+ it "initializes filterrific_filter_names" do
48
+ filterrific_class.filterrific_filter_names.must_equal(TestData.filterrific_filter_names)
49
+ end
50
+
51
+ it "initializes filterrific_default_settings" do
52
+ filterrific_class.filterrific_default_settings.must_equal(TestData.filterrific_default_settings)
53
+ end
54
+
55
+ it "raises when no filter_names are given" do
56
+ proc {
57
+ Class.new(ActiveRecord::Base) do
58
+ filterrific(
59
+ :filter_names => []
60
+ )
61
+ end
62
+ }.must_raise(ArgumentError)
63
+ end
64
+
65
+ it "raises when default_settings contains keys that are not in filter_names" do
66
+ proc {
67
+ Class.new(ActiveRecord::Base) do
68
+ filterrific(
69
+ :filter_names => [:one, :two],
70
+ :default_settings => { :three => '' }
71
+ )
72
+ end
73
+ }.must_raise(ArgumentError)
74
+ end
75
+
76
+ end
77
+
78
+ describe "filterrific_find" do
79
+
80
+ it "raises when given invalid params" do
81
+ proc {
82
+ filterrific_class.filterrific_find('an invalid argument')
83
+ }.must_raise(ArgumentError)
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+ require 'filterrific/param_set'
3
+
4
+ module Filterrific
5
+
6
+ # Container for test data
7
+ class TestData
8
+
9
+ def self.filterrific_filter_names
10
+ %w[
11
+ filter_proc
12
+ filter_array_int
13
+ filter_array_string
14
+ filter_int
15
+ filter_string
16
+ ]
17
+ end
18
+
19
+ def self.filterrific_default_settings
20
+ { 'filter_int' => 42 }
21
+ end
22
+
23
+ def self.filterrific_params
24
+ {
25
+ 'filter_proc' => lambda { 1 + 1 },
26
+ 'filter_array_int' => %w[1 2 3],
27
+ 'filter_array_string' => %w[one two three],
28
+ 'filter_int' => '42',
29
+ 'filter_string' => 'forty-two'
30
+ }
31
+ end
32
+
33
+ def self.filterrific_params_after_sanitizing
34
+ {
35
+ 'filter_proc' => 2,
36
+ 'filter_array_int' => [1, 2, 3],
37
+ 'filter_array_string' => %w[one two three],
38
+ 'filter_int' => 42,
39
+ 'filter_string' => 'forty-two'
40
+ }
41
+ end
42
+
43
+ end
44
+
45
+ # Simulates a class that would include the filterrific directive
46
+ class ResourceClass
47
+
48
+ def self.filterrific_default_settings
49
+ TestData.filterrific_default_settings
50
+ end
51
+ def self.filterrific_filter_names
52
+ TestData.filterrific_filter_names
53
+ end
54
+
55
+ end
56
+
57
+ describe ParamSet do
58
+
59
+ let(:filterrific_param_set){
60
+ Filterrific::ParamSet.new(ResourceClass, TestData.filterrific_params)
61
+ }
62
+
63
+ describe "initialization" do
64
+
65
+ it "assigns resource class" do
66
+ filterrific_param_set.resource_class.must_equal(ResourceClass)
67
+ end
68
+
69
+ describe "dynamic filter_name attr_accessors" do
70
+
71
+ TestData.filterrific_filter_names.each do |filter_name|
72
+
73
+ it "defines a getter for '#{ filter_name }'" do
74
+ filterrific_param_set.must_respond_to(filter_name)
75
+ end
76
+
77
+ it "defines a setter for '#{ filter_name }'" do
78
+ filterrific_param_set.must_respond_to("#{ filter_name }=")
79
+ end
80
+
81
+ end
82
+
83
+ TestData.filterrific_params.keys.each do |key|
84
+
85
+ it "assigns sanitized param to '#{ key }' attr" do
86
+ filterrific_param_set.send(key).must_equal(TestData.filterrific_params_after_sanitizing[key])
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ describe "to_hash" do
96
+
97
+ it "returns all filterrific_params as hash" do
98
+ filterrific_param_set.to_hash.must_equal(TestData.filterrific_params_after_sanitizing)
99
+ end
100
+
101
+ end
102
+
103
+ describe "to_json" do
104
+
105
+ it "returns all filterrific_params as json string" do
106
+ filterrific_param_set.to_json.must_equal(TestData.filterrific_params_after_sanitizing.to_json)
107
+ end
108
+
109
+ end
110
+
111
+ describe "#select_options" do
112
+ it "exists" do
113
+ filterrific_param_set.select_options.must_equal({})
114
+ end
115
+
116
+ it "lets you assign a hash" do
117
+ # Make sure it doesn't raise an exception
118
+ filterrific_param_set.select_options = {}
119
+ 1.must_equal(1)
120
+ end
121
+
122
+ it "lets you set a value" do
123
+ # Make sure it doesn't raise an exception
124
+ filterrific_param_set.select_options[:value] = 1
125
+ 1.must_equal(1)
126
+ end
127
+
128
+ it "returns the same value you set" do
129
+ value = rand(1..200)
130
+ filterrific_param_set.select_options[:value] = value
131
+ filterrific_param_set.select_options[:value].must_equal(value)
132
+ end
133
+ end
134
+
135
+ end
136
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Filterrific do
4
- pending "write it"
5
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'rubygems'
1
+ ENV["RAILS_ENV"] = "test"
2
2
  require 'bundler/setup'
3
+ require 'minitest/autorun'
4
+ require 'rails'
5
+ require 'filterrific'
3
6
 
4
- RSpec.configure do |config|
5
- # Nothing to do
6
- end
7
+ #MiniTest::Unit.autorun
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterrific
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Hund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 3.1.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.0
26
+ version: 3.1.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.6.1
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
- version: '0'
40
+ version: 1.6.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: gem-release
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.0
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
- version: 1.0.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 10.3.2
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
- version: '0'
68
+ version: 10.3.2
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec-rails
70
+ name: wwtd
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.5.5
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
- version: '0'
82
+ version: 0.5.5
83
83
  description: Filterrific is a Rails Engine plugin that makes it easy to add filtering,
84
84
  searching, and sorting to your ActiveRecord lists.
85
85
  email: jhund@clearcove.ca
@@ -91,6 +91,9 @@ files:
91
91
  - MIT-LICENSE
92
92
  - README.md
93
93
  - Rakefile
94
+ - app/assets/images/filterrific/filterrific-spinner.gif
95
+ - app/assets/javascripts/filterrific/filterrific-jquery.js
96
+ - bin/rails
94
97
  - doc/Overview diagram.graffle/data.plist
95
98
  - doc/Overview diagram.graffle/image1.tiff
96
99
  - doc/development_notes/api_design.txt
@@ -98,19 +101,18 @@ files:
98
101
  - doc/development_notes/model_api.rb
99
102
  - doc/development_notes/view_api.txt
100
103
  - doc/meta.md
104
+ - doc/scratchpad.md
101
105
  - lib/filterrific.rb
102
106
  - lib/filterrific/action_view_extension.rb
103
107
  - lib/filterrific/active_record_extension.rb
104
108
  - lib/filterrific/engine.rb
105
109
  - lib/filterrific/param_set.rb
106
110
  - lib/filterrific/version.rb
107
- - spec/action_view_extension_spec.rb
108
- - spec/active_record_extension_spec.rb
111
+ - spec/filterrific/action_view_extension_spec.rb
112
+ - spec/filterrific/active_record_extension_spec.rb
113
+ - spec/filterrific/param_set_spec.rb
109
114
  - spec/filterrific_spec.rb
110
- - spec/param_set_spec.rb
111
115
  - spec/spec_helper.rb
112
- - vendor/assets/images/filterrific-spinner.gif
113
- - vendor/assets/javascripts/filterrific-jquery.js
114
116
  homepage: http://filterrific.clearcove.ca
115
117
  licenses:
116
118
  - MIT
@@ -131,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  version: '0'
132
134
  requirements: []
133
135
  rubyforge_project:
134
- rubygems_version: 2.2.1
136
+ rubygems_version: 2.2.2
135
137
  signing_key:
136
138
  specification_version: 4
137
139
  summary: A Rails engine plugin for filtering ActiveRecord lists.
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
- require 'filterrific/action_view_extension'
3
-
4
- class ViewContext
5
-
6
- include Filterrific::ActionViewExtension
7
-
8
- end
9
-
10
- describe Filterrific::ActionViewExtension do
11
-
12
- it "renders filterrific spinner" do
13
- ViewContext.new.should respond_to(:render_filterrific_spinner)
14
- end
15
-
16
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_record'
3
- require 'filterrific/active_record_extension'
4
- ::ActiveRecord::Base.extend Filterrific::ActiveRecordExtension::ClassMethods
5
-
6
- # Container for test data
7
- class TestData
8
-
9
- def self.filterrific_filter_names
10
- %w[sorted_by search_query with_country_id]
11
- end
12
-
13
- def self.filterrific_default_settings
14
- { 'sorted_by' => 'name_asc' }
15
- end
16
-
17
- end
18
-
19
- describe Filterrific::ActiveRecordExtension do
20
-
21
- let(:filterrific_class){
22
- Class.new(ActiveRecord::Base) do
23
- filterrific(
24
- :filter_names => TestData.filterrific_filter_names,
25
- :default_settings => TestData.filterrific_default_settings
26
- )
27
- end
28
- }
29
-
30
- describe "Class method extensions" do
31
-
32
- it "adds a 'filterrific' class method" do
33
- filterrific_class.should respond_to(:filterrific)
34
- end
35
-
36
- it "adds a 'filterrific_find' class method" do
37
- filterrific_class.should respond_to(:filterrific_find)
38
- end
39
-
40
- end
41
-
42
- describe "Filterrific initialization" do
43
-
44
- it "initializes filterrific_filter_names" do
45
- filterrific_class.filterrific_filter_names.should == TestData.filterrific_filter_names
46
- end
47
-
48
- it "initializes filterrific_default_settings" do
49
- filterrific_class.filterrific_default_settings.should == TestData.filterrific_default_settings
50
- end
51
-
52
- it "raises when no filter_names are given" do
53
- expect {
54
- Class.new(ActiveRecord::Base) do
55
- filterrific(
56
- :filter_names => []
57
- )
58
- end
59
- }.to raise_error(ArgumentError)
60
- end
61
-
62
- it "raises when default_settings contains keys that are not in filter_names" do
63
- expect {
64
- Class.new(ActiveRecord::Base) do
65
- filterrific(
66
- :filter_names => [:one, :two],
67
- :default_settings => { :three => '' }
68
- )
69
- end
70
- }.to raise_error(ArgumentError)
71
- end
72
-
73
- end
74
-
75
- describe "filterrific_find" do
76
-
77
- it "raises when given invalid params" do
78
- expect {
79
- filterrific_class.filterrific_find('an invalid argument')
80
- }.to raise_error(ArgumentError)
81
- end
82
-
83
- end
84
-
85
- end
@@ -1,129 +0,0 @@
1
- require 'spec_helper'
2
- require 'filterrific/param_set'
3
-
4
- # Container for test data
5
- class TestData
6
-
7
- def self.filterrific_filter_names
8
- %w[
9
- filter_proc
10
- filter_array_int
11
- filter_array_string
12
- filter_int
13
- filter_string
14
- ]
15
- end
16
-
17
- def self.filterrific_default_settings
18
- { 'filter_int' => 42 }
19
- end
20
-
21
- def self.filterrific_params
22
- {
23
- 'filter_proc' => lambda { 1 + 1 },
24
- 'filter_array_int' => %w[1 2 3],
25
- 'filter_array_string' => %w[one two three],
26
- 'filter_int' => '42',
27
- 'filter_string' => 'forty-two'
28
- }
29
- end
30
-
31
- def self.filterrific_params_after_sanitizing
32
- {
33
- 'filter_proc' => 2,
34
- 'filter_array_int' => [1, 2, 3],
35
- 'filter_array_string' => %w[one two three],
36
- 'filter_int' => 42,
37
- 'filter_string' => 'forty-two'
38
- }
39
- end
40
-
41
- end
42
-
43
- # Simulates a class that would include the filterrific directive
44
- class ResourceClass
45
-
46
- def self.filterrific_default_settings
47
- TestData.filterrific_default_settings
48
- end
49
- def self.filterrific_filter_names
50
- TestData.filterrific_filter_names
51
- end
52
-
53
- end
54
-
55
- describe Filterrific::ParamSet do
56
-
57
- let(:filterrific_param_set){
58
- Filterrific::ParamSet.new(ResourceClass, TestData.filterrific_params)
59
- }
60
-
61
- describe "initialization" do
62
-
63
- it "assigns resource class" do
64
- filterrific_param_set.resource_class.should == ResourceClass
65
- end
66
-
67
- describe "dynamic filter_name attr_accessors" do
68
-
69
- TestData.filterrific_filter_names.each do |filter_name|
70
-
71
- it "defines a getter for '#{ filter_name }'" do
72
- filterrific_param_set.should respond_to(filter_name)
73
- end
74
-
75
- it "defines a setter for '#{ filter_name }'" do
76
- filterrific_param_set.should respond_to("#{ filter_name }=")
77
- end
78
-
79
- end
80
-
81
- TestData.filterrific_params.keys.each do |key|
82
-
83
- it "assigns sanitized param to '#{ key }' attr" do
84
- filterrific_param_set.send(key).should == TestData.filterrific_params_after_sanitizing[key]
85
- end
86
-
87
- end
88
-
89
- end
90
-
91
- end
92
-
93
- describe "to_hash" do
94
-
95
- it "returns all filterrific_params as hash" do
96
- filterrific_param_set.to_hash.should == TestData.filterrific_params_after_sanitizing
97
- end
98
-
99
- end
100
-
101
- describe "to_json" do
102
-
103
- it "returns all filterrific_params as json string" do
104
- filterrific_param_set.to_json.should == TestData.filterrific_params_after_sanitizing.to_json
105
- end
106
-
107
- end
108
-
109
- describe "#select_options" do
110
- it "exists" do
111
- expect(filterrific_param_set.select_options).to eq({})
112
- end
113
-
114
- it "lets you assign a hash" do
115
- expect{filterrific_param_set.select_options = {}}.not_to raise_error
116
- end
117
-
118
- it "lets you set a value" do
119
- expect{filterrific_param_set.select_options[:value] = 1}.not_to raise_error
120
- end
121
-
122
- it "returns the same value you set" do
123
- value = rand(1..200)
124
- filterrific_param_set.select_options[:value] = value
125
- expect(filterrific_param_set.select_options[:value]).to eq(value)
126
- end
127
- end
128
-
129
- end