filterism 1.0.0 → 2.0.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.
@@ -1,91 +0,0 @@
1
- require 'helper'
2
- require 'finders/activerecord_test_connector'
3
- ActiverecordTestConnector.setup
4
-
5
- describe Filterism do
6
- extend ActiverecordTestConnector::FixtureSetup
7
- fixtures :users
8
- fixtures :posts
9
-
10
- it "defines the COMPARATORS constant" do
11
- Filterism::COMPARATORS.should be
12
- Filterism::COMPARATORS.should be_a Hash
13
- end
14
-
15
- it "fitlers on equal_to" do
16
- User.filter({'name_is_equal_to' => 'David'}).first.id.should == 1
17
- User.filter({'name_is_equal_to' => 'Dave'}).first.id.should == 2
18
- end
19
-
20
- it "filters on not_equal_to" do
21
- User.filter({'name_is_not_equal_to' => 'David'}).all.count.should == 4
22
- end
23
-
24
- it "filters on greater_than" do
25
- User.filter({'salary_is_greater_than' => '80000'}).all.count.should == 1
26
- end
27
-
28
- it "filters on gt" do
29
- User.filter({'salary_is_gt' => '70000'}).all.count.should == 2
30
- end
31
-
32
- it "filters on after" do
33
- User.filter({'salary_is_after' => '9000'}).all.count.should == 4
34
- end
35
-
36
- it "filters on greater_than_or_equal_to" do
37
- User.filter({'salary_is_greater_than_or_equal_to' => '80000'}).all.count.should == 2
38
- end
39
-
40
- it "filters on gtet" do
41
- User.filter({'salary_is_gtet' => '80000'}).all.count.should == 2
42
- end
43
-
44
- it "filters on less_than" do
45
- User.filter({'salary_is_less_than' => '80000'}).all.count.should == 3
46
- end
47
-
48
- it "filters on lt" do
49
- User.filter({'salary_is_lt' => '70000'}).all.count.should == 3
50
- end
51
-
52
- it "filters on before" do
53
- User.filter({'salary_is_before' => '10000'}).all.count.should == 1
54
- end
55
-
56
- it "filters on less_than_or_equal_to" do
57
- User.filter({'salary_is_less_than_or_equal_to' => '80000'}).all.count.should == 4
58
- end
59
-
60
- it "filters on ltet" do
61
- User.filter({'salary_is_ltet' => '80000'}).all.count.should == 4
62
- end
63
-
64
- it "filters on like" do
65
- User.filter({'name_is_like' => 'Dav'}).all.count.should == 2
66
- end
67
-
68
- it "filters on in" do
69
- User.filter({'id_is_in' => '1,2,3'}).all.count.should == 3
70
- User.filter({'name_is_in' => 'Dave,Jamis'}).all.count.should == 2
71
- end
72
-
73
- it "fitlers on multiple expressions" do
74
- User.filter({'name_is_in' => 'Dave,Jamis,David', 'salary_is_gt' => '10000'}).all.count.should == 2
75
- end
76
-
77
- it "handles booleans properly" do
78
- User.filter({'bonus_is_equal_to' => 'true'}).all.count.should == 3
79
-
80
- end
81
-
82
- it "doesn't filter if passed invalid expression" do
83
- User.filter({'name_is_garbage' => 'David'}).all.count.should == User.all.count
84
- end
85
-
86
- it "uses filterable fields" do
87
- Post.filter({'title_is_equal_to' => 'Post 1 title'}).all.count.should == 1
88
- Post.filter({'body_is_equal_to' => 'Post 1 body'}).all.count.should == 3
89
- end
90
-
91
- end
@@ -1,104 +0,0 @@
1
- require 'active_record'
2
- require 'active_record/version'
3
- require 'active_record/fixtures'
4
- require 'active_support/multibyte' # needed for Ruby 1.9.1
5
-
6
- $query_count = $query_sql = nil
7
-
8
- module ActiverecordTestConnector
9
- extend self
10
-
11
- attr_accessor :able_to_connect
12
- attr_accessor :connected
13
-
14
- FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
15
-
16
- # Set our defaults
17
- self.connected = false
18
- self.able_to_connect = true
19
-
20
- def setup
21
- unless self.connected || !self.able_to_connect
22
- setup_connection
23
- load_schema
24
- add_load_path FIXTURES_PATH
25
- self.connected = true
26
- end
27
- rescue Exception => e # errors from ActiveRecord setup
28
- $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
29
- self.able_to_connect = false
30
- end
31
-
32
- private
33
-
34
- def add_load_path(path)
35
- dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
36
- dep.autoload_paths.unshift path
37
- end
38
-
39
- def setup_connection
40
- ActiveRecord::Base.establish_connection(
41
- :adapter => "sqlite3",
42
- :database => ":memory:"
43
- )
44
- prepare ActiveRecord::Base.connection
45
- end
46
-
47
- def load_schema
48
- ActiveRecord::Base.silence do
49
- ActiveRecord::Migration.verbose = false
50
- load File.join(FIXTURES_PATH, 'schema.rb')
51
- end
52
- end
53
-
54
- def prepare(conn)
55
- class << conn
56
- IGNORED_SQL = /^(?:PRAGMA|SELECT (?:currval|CAST|@@IDENTITY|@@ROWCOUNT)|SHOW FIELDS)\b/
57
-
58
- def execute_with_counting(sql, name = nil, &block)
59
- if $query_count and IGNORED_SQL !~ sql
60
- $query_count += 1
61
- $query_sql << sql
62
- end
63
- execute_without_counting(sql, name, &block)
64
- end
65
-
66
- alias_method_chain :execute, :counting
67
- end
68
- end
69
-
70
- module FixtureSetup
71
- def fixtures(*tables)
72
- table_names = tables.map { |t| t.to_s }
73
-
74
- fixtures = Fixtures.create_fixtures ActiverecordTestConnector::FIXTURES_PATH, table_names
75
- @@loaded_fixtures = {}
76
- @@fixture_cache = {}
77
-
78
- unless fixtures.nil?
79
- if fixtures.instance_of?(Fixtures)
80
- @@loaded_fixtures[fixtures.table_name] = fixtures
81
- else
82
- fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
83
- end
84
- end
85
-
86
- table_names.each do |table_name|
87
- define_method(table_name) do |*fixtures|
88
- @@fixture_cache[table_name] ||= {}
89
-
90
- instances = fixtures.map do |fixture|
91
- if @@loaded_fixtures[table_name][fixture.to_s]
92
- @@fixture_cache[table_name][fixture] ||= @@loaded_fixtures[table_name][fixture.to_s].find
93
- else
94
- raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
95
- end
96
- end
97
-
98
- instances.size == 1 ? instances.first : instances
99
- end
100
- end
101
- end
102
- end
103
- end
104
-
@@ -1,3 +0,0 @@
1
- class Post < ActiveRecord::Base
2
- filterable_fields :title, :published_at
3
- end
@@ -1,16 +0,0 @@
1
- post1:
2
- id: 1
3
- title: "Post 1 title"
4
- body: "Post 1 body"
5
-
6
- post2:
7
- id: 2
8
- title: "Post 2 title"
9
- body: "Post 2 body"
10
-
11
- post3:
12
- id: 3
13
- title: "Post 3 title"
14
- body: "Post 3 body"
15
-
16
-
@@ -1,17 +0,0 @@
1
- ActiveRecord::Schema.define do
2
- create_table "users", :force => true do |t|
3
- t.column "name", :text
4
- t.column "salary", :integer, :default => 70000
5
- t.column "bonus", :boolean, :default => false
6
- t.column "created_at", :datetime
7
- t.column "updated_at", :datetime
8
- end
9
-
10
- create_table "posts", :force => true do |t|
11
- t.column "title", :string
12
- t.column "body", :text
13
- t.column "published_at", :datetime
14
- t.column "created_at", :datetime
15
- t.column "updated_at", :datetime
16
- end
17
- end
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,30 +0,0 @@
1
- david:
2
- id: 1
3
- name: David
4
- salary: 80000
5
- bonus: true
6
-
7
- dave:
8
- id: 2
9
- name: Dave
10
- salary: 150000
11
- bonus: true
12
-
13
- poor_jamis:
14
- id: 3
15
- name: Jamis
16
- salary: 9000
17
- bonus: true
18
-
19
- admin:
20
- id: 12
21
- name: admin
22
- salary: 10000
23
- bonus: false
24
-
25
- goofy:
26
- id: 13
27
- name: Goofy
28
- salary: 11000
29
- bonus: false
30
-
@@ -1,6 +0,0 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
3
- require 'simplecov'
4
- SimpleCov.start
5
- require 'filterism'
6
- require 'rspec'