activerecord-like 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -2
- data/Gemfile +8 -1
- data/README.md +1 -0
- data/activerecord-like.gemspec +1 -1
- data/lib/active_record/like/version.rb +1 -1
- data/test/helper.rb +94 -1
- data/test/integration/like_test.rb +1 -1
- data/test/integration/not_like_test.rb +1 -1
- metadata +11 -5
data/.travis.yml
CHANGED
@@ -3,5 +3,10 @@ cache: bundler
|
|
3
3
|
rvm:
|
4
4
|
- 1.9.3
|
5
5
|
- rbx-2.1.1
|
6
|
-
|
7
|
-
|
6
|
+
env:
|
7
|
+
- DB=pg
|
8
|
+
- DB=sqlite3
|
9
|
+
- DB=mysql
|
10
|
+
before_script:
|
11
|
+
- psql -c 'create database activerecord_like_test' -U postgres
|
12
|
+
- mysql -e 'create database activerecord_like_test'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/ReneB/activerecord-like.png?branch=master)](https://travis-ci.org/ReneB/activerecord-like)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/ReneB/activerecord-like.png)](https://codeclimate.com/github/ReneB/activerecord-like)
|
5
5
|
[![Dependency Status](https://gemnasium.com/ReneB/activerecord-like.png)](https://gemnasium.com/ReneB/activerecord-like)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/activerecord-like.png)](http://badge.fury.io/rb/activerecord-like)
|
6
7
|
|
7
8
|
An Active Record Plugin that allows chaining a more DSL-style 'like' or 'not-like' query to an ActiveRecord::Base#where. Requires Rails 4 beta or higher.
|
8
9
|
|
data/activerecord-like.gemspec
CHANGED
data/test/helper.rb
CHANGED
@@ -3,7 +3,100 @@ require 'minitest/autorun'
|
|
3
3
|
require 'minitest/spec'
|
4
4
|
require 'active_record/like'
|
5
5
|
|
6
|
-
|
6
|
+
module Test
|
7
|
+
module Postgres
|
8
|
+
def connect_db
|
9
|
+
ActiveRecord::Base.establish_connection(postgres_config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def drop_and_create_database
|
13
|
+
# drops and create need to be performed with a connection to the 'postgres' (system) database
|
14
|
+
temp_connection = postgres_config.merge(database: 'postgres', schema_search_path: 'public')
|
15
|
+
ActiveRecord::Base.establish_connection(temp_connection)
|
16
|
+
|
17
|
+
# drop the old database (if it exists)
|
18
|
+
ActiveRecord::Base.connection.drop_database(database_name) rescue nil
|
19
|
+
|
20
|
+
# create new
|
21
|
+
ActiveRecord::Base.connection.create_database(database_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def postgres_config
|
25
|
+
@postgres_config ||= {
|
26
|
+
adapter: 'postgresql',
|
27
|
+
database: database_name,
|
28
|
+
username: 'postgres'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def database_name
|
33
|
+
'activerecord_like_test'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module SQLite3
|
38
|
+
def connect_db
|
39
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
40
|
+
end
|
41
|
+
|
42
|
+
def drop_and_create_database
|
43
|
+
# NOOP for SQLite3
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module MySQL
|
48
|
+
def connect_db
|
49
|
+
ActiveRecord::Base.establish_connection(mysql_config)
|
50
|
+
end
|
51
|
+
|
52
|
+
def drop_and_create_database
|
53
|
+
temp_connection = mysql_config.merge(database: 'mysql')
|
54
|
+
|
55
|
+
ActiveRecord::Base.establish_connection(temp_connection)
|
56
|
+
|
57
|
+
# drop the old database (if it exists)
|
58
|
+
ActiveRecord::Base.connection.drop_database(database_name) rescue nil
|
59
|
+
|
60
|
+
# create new
|
61
|
+
ActiveRecord::Base.connection.create_database(database_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def mysql_config
|
65
|
+
@mysql_config ||= {
|
66
|
+
adapter: 'mysql2',
|
67
|
+
database: database_name,
|
68
|
+
username: db_user_name,
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def db_user_name
|
73
|
+
# change this to whatever your config requires
|
74
|
+
ENV['TRAVIS'] ? 'travis' : 'root'
|
75
|
+
end
|
76
|
+
|
77
|
+
def database_name
|
78
|
+
'activerecord_like_test'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
case ENV['DB']
|
84
|
+
when 'pg'
|
85
|
+
include Test::Postgres
|
86
|
+
when 'sqlite3'
|
87
|
+
include Test::SQLite3
|
88
|
+
when 'mysql'
|
89
|
+
include Test::MySQL
|
90
|
+
else
|
91
|
+
puts "No DB environment variable provided, testing using SQLite3"
|
92
|
+
include Test::SQLite3
|
93
|
+
end
|
94
|
+
|
95
|
+
unless ENV['TRAVIS'] # if we're running on Travis, no drop/create needed
|
96
|
+
drop_and_create_database
|
97
|
+
end
|
98
|
+
|
99
|
+
connect_db
|
7
100
|
|
8
101
|
ActiveRecord::Schema.verbose = false
|
9
102
|
ActiveRecord::Schema.define do
|
@@ -36,7 +36,7 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
36
36
|
|
37
37
|
describe "security-related behavior" do
|
38
38
|
before do
|
39
|
-
@user_input = "unused%' OR 1=1); --"
|
39
|
+
@user_input = "unused%' OR 1=1); -- "
|
40
40
|
end
|
41
41
|
|
42
42
|
# This test is only here to provide the contrast for the test below
|
@@ -36,7 +36,7 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
36
36
|
|
37
37
|
describe "security-related behavior" do
|
38
38
|
before do
|
39
|
-
@user_input = "unused%' OR 1=1); --"
|
39
|
+
@user_input = "unused%' OR 1=1); -- "
|
40
40
|
end
|
41
41
|
|
42
42
|
# This test is only here to provide the contrast for the test below
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-like
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: 4.0.2
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 4.0.2
|
46
46
|
description: An ActiveRecord plugin providing a higher-level abstraction for SQL 'LIKE'
|
@@ -78,15 +78,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- - ! '>='
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
hash: 3561638004466154601
|
81
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
85
|
none: false
|
83
86
|
requirements:
|
84
87
|
- - ! '>='
|
85
88
|
- !ruby/object:Gem::Version
|
86
89
|
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 3561638004466154601
|
87
93
|
requirements: []
|
88
94
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.8.
|
95
|
+
rubygems_version: 1.8.24
|
90
96
|
signing_key:
|
91
97
|
specification_version: 3
|
92
98
|
summary: ! 'ActiveRecord::Like provides ActiveRecord::Base with where.like(attribute:
|