redirector 1.1.1 → 1.1.2
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 +4 -4
- data/app/models/redirect_rule.rb +13 -2
- data/lib/redirector/regex_attribute.rb +9 -6
- data/lib/redirector/version.rb +1 -1
- data/redirector.gemspec +2 -1
- data/spec/dummy/db/schema.rb +23 -23
- data/spec/dummy/log/development.log +20 -0
- data/spec/models/redirect_rule_spec.rb +1 -1
- data/spec/models/request_environment_rule_spec.rb +4 -3
- data/spec/spec_helper.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3795c5f05e3924521efe95b4fae87fb6f54ff8175cd42f57270923135e3eddc8
|
4
|
+
data.tar.gz: 8782cb91c17c0e50aef45016a99d413db0bd8543705c14123a4c59806834c8c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcadbff5bc278f14d9496838ee1069d4383bde0a75cd8a1fec00b9837e097c0c8f05449a997619a77647d5d17bf5fc10b81e9563d2aa419ac6b7d56eb2b8b9c7
|
7
|
+
data.tar.gz: e416e72e42dfcdb817a620cdbdc9ca64a9d37fcbe3a274562f99f4e0122e7b72878e2081748046825d66e80d3544cac9c13ad7560fcf8f5e383d3c6df84a6cc7
|
data/app/models/redirect_rule.rb
CHANGED
@@ -14,7 +14,11 @@ class RedirectRule < ActiveRecord::Base
|
|
14
14
|
accepts_nested_attributes_for :request_environment_rules, :allow_destroy => true, :reject_if => :all_blank
|
15
15
|
|
16
16
|
validates :source, :destination, :presence => true
|
17
|
-
|
17
|
+
|
18
|
+
# Not working with rails 5.0.1
|
19
|
+
if Rails.version.to_i < 5
|
20
|
+
validates :active, :inclusion => { :in => ['0', '1', true, false] }
|
21
|
+
end
|
18
22
|
|
19
23
|
before_save :strip_source_whitespace
|
20
24
|
|
@@ -22,6 +26,9 @@ class RedirectRule < ActiveRecord::Base
|
|
22
26
|
if connection_mysql?
|
23
27
|
'(redirect_rules.source_is_case_sensitive = :true AND :source REGEXP BINARY redirect_rules.source) OR '+
|
24
28
|
'(redirect_rules.source_is_case_sensitive = :false AND :source REGEXP redirect_rules.source)'
|
29
|
+
elsif connection_sqlite?
|
30
|
+
'(redirect_rules.source_is_case_sensitive = :true AND :source REGEXP redirect_rules.source COLLATE BINARY) OR '+
|
31
|
+
'(redirect_rules.source_is_case_sensitive = :false AND :source REGEXP redirect_rules.source)'
|
25
32
|
else
|
26
33
|
'(redirect_rules.source_is_case_sensitive = :true AND :source ~ redirect_rules.source) OR '+
|
27
34
|
'(redirect_rules.source_is_case_sensitive = :false AND :source ~* redirect_rules.source)'
|
@@ -32,7 +39,7 @@ class RedirectRule < ActiveRecord::Base
|
|
32
39
|
<<-SQL
|
33
40
|
redirect_rules.active = :true AND
|
34
41
|
((source_is_regex = :false AND source_is_case_sensitive = :false AND LOWER(redirect_rules.source) = LOWER(:source)) OR
|
35
|
-
(source_is_regex = :false AND source_is_case_sensitive = :true AND #{'BINARY' if connection_mysql?} redirect_rules.source = :source) OR
|
42
|
+
(source_is_regex = :false AND source_is_case_sensitive = :true AND #{'BINARY' if connection_mysql?} redirect_rules.source = :source #{'COLLATE BINARY' if connection_sqlite?}) OR
|
36
43
|
(source_is_regex = :true AND (#{regex_expression})))
|
37
44
|
SQL
|
38
45
|
end
|
@@ -74,6 +81,10 @@ class RedirectRule < ActiveRecord::Base
|
|
74
81
|
connection.adapter_name.downcase.include?('mysql')
|
75
82
|
end
|
76
83
|
|
84
|
+
def self.connection_sqlite?
|
85
|
+
connection.adapter_name.downcase.include?('sqlite')
|
86
|
+
end
|
87
|
+
|
77
88
|
def strip_source_whitespace
|
78
89
|
self.source = self.source.strip
|
79
90
|
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
module Redirector
|
2
2
|
module RegexAttribute
|
3
|
-
|
3
|
+
|
4
4
|
def regex_attribute(attribute_name)
|
5
5
|
include ValidationMethod
|
6
6
|
|
7
7
|
cattr_accessor :regex_attribute_name
|
8
8
|
self.regex_attribute_name = attribute_name
|
9
9
|
|
10
|
-
validates "#{attribute_name}_is_regex".to_sym, :inclusion => { :in => ['0', '1', true, false] }
|
11
|
-
validates "#{attribute_name}_is_case_sensitive".to_sym, :inclusion => { :in => ['0', '1', true, false] }
|
12
10
|
validate :regex_attribute_is_valid_regex
|
11
|
+
# Not working with rails 5.0.1
|
12
|
+
if Rails.version.to_i < 5
|
13
|
+
validates "#{attribute_name}_is_regex".to_sym, :inclusion => { :in => ['0', '1', true, false] }
|
14
|
+
validates "#{attribute_name}_is_case_sensitive".to_sym, :inclusion => { :in => ['0', '1', true, false] }
|
15
|
+
end
|
13
16
|
|
14
17
|
define_method("#{regex_attribute_name}_regex") do
|
15
18
|
if self.send("#{regex_attribute_name}_is_case_sensitive?")
|
@@ -19,11 +22,11 @@ module Redirector
|
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
22
|
-
|
25
|
+
|
23
26
|
module ValidationMethod
|
24
|
-
|
27
|
+
|
25
28
|
protected
|
26
|
-
|
29
|
+
|
27
30
|
def regex_attribute_is_valid_regex
|
28
31
|
if self.send("#{regex_attribute_name}_is_regex?") && self.send("#{regex_attribute_name}?")
|
29
32
|
begin
|
data/lib/redirector/version.rb
CHANGED
data/redirector.gemspec
CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = Dir["spec/**/*"]
|
19
19
|
|
20
20
|
s.add_dependency "rails", ">= 3.1"
|
21
|
-
# s.add_dependency "jquery-rails"
|
22
21
|
|
23
22
|
s.add_development_dependency "mysql2"
|
24
23
|
s.add_development_dependency "pg"
|
24
|
+
|
25
25
|
s.add_development_dependency 'rspec-rails', '~> 3.7'
|
26
|
+
s.add_development_dependency "sqlite3"
|
26
27
|
s.add_development_dependency 'shoulda-matchers'
|
27
28
|
s.add_development_dependency 'capybara', '~> 2.2'
|
28
29
|
s.add_development_dependency 'database_cleaner'
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -9,35 +9,35 @@
|
|
9
9
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
10
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
11
|
#
|
12
|
-
# It's strongly recommended
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:
|
14
|
+
ActiveRecord::Schema.define(version: 20120823163756) do
|
15
15
|
|
16
|
-
create_table "redirect_rules", :
|
17
|
-
t.string "source",
|
18
|
-
t.boolean "source_is_regex", :default
|
19
|
-
t.boolean "source_is_case_sensitive", :default
|
20
|
-
t.string "destination",
|
21
|
-
t.boolean "active", :default
|
22
|
-
t.datetime "created_at"
|
23
|
-
t.datetime "updated_at"
|
16
|
+
create_table "redirect_rules", force: :cascade do |t|
|
17
|
+
t.string "source", limit: 255, null: false
|
18
|
+
t.boolean "source_is_regex", limit: 1, default: false, null: false
|
19
|
+
t.boolean "source_is_case_sensitive", limit: 1, default: false, null: false
|
20
|
+
t.string "destination", limit: 255, null: false
|
21
|
+
t.boolean "active", limit: 1, default: false
|
22
|
+
t.datetime "created_at"
|
23
|
+
t.datetime "updated_at"
|
24
24
|
end
|
25
25
|
|
26
|
-
add_index "redirect_rules", ["active"], :
|
27
|
-
add_index "redirect_rules", ["source"], :
|
28
|
-
add_index "redirect_rules", ["source_is_case_sensitive"], :
|
29
|
-
add_index "redirect_rules", ["source_is_regex"], :
|
26
|
+
add_index "redirect_rules", ["active"], name: "index_redirect_rules_on_active", using: :btree
|
27
|
+
add_index "redirect_rules", ["source"], name: "index_redirect_rules_on_source", using: :btree
|
28
|
+
add_index "redirect_rules", ["source_is_case_sensitive"], name: "index_redirect_rules_on_source_is_case_sensitive", using: :btree
|
29
|
+
add_index "redirect_rules", ["source_is_regex"], name: "index_redirect_rules_on_source_is_regex", using: :btree
|
30
30
|
|
31
|
-
create_table "request_environment_rules", :
|
32
|
-
t.integer "redirect_rule_id",
|
33
|
-
t.string "environment_key_name",
|
34
|
-
t.string "environment_value",
|
35
|
-
t.boolean "environment_value_is_regex", :default
|
36
|
-
t.boolean "environment_value_is_case_sensitive", :default
|
37
|
-
t.datetime "created_at"
|
38
|
-
t.datetime "updated_at"
|
31
|
+
create_table "request_environment_rules", force: :cascade do |t|
|
32
|
+
t.integer "redirect_rule_id", limit: 4, null: false
|
33
|
+
t.string "environment_key_name", limit: 255, null: false
|
34
|
+
t.string "environment_value", limit: 255, null: false
|
35
|
+
t.boolean "environment_value_is_regex", limit: 1, default: false, null: false
|
36
|
+
t.boolean "environment_value_is_case_sensitive", limit: 1, default: true, null: false
|
37
|
+
t.datetime "created_at"
|
38
|
+
t.datetime "updated_at"
|
39
39
|
end
|
40
40
|
|
41
|
-
add_index "request_environment_rules", ["redirect_rule_id"], :
|
41
|
+
add_index "request_environment_rules", ["redirect_rule_id"], name: "index_request_environment_rules_on_redirect_rule_id", using: :btree
|
42
42
|
|
43
43
|
end
|
@@ -34,3 +34,23 @@ Migrating to CreateRequestEnvironmentRules (20120823163756)
|
|
34
34
|
[1m[35m (0.2ms)[0m [1m[35mCOMMIT[0m
|
35
35
|
[1m[35m (0.1ms)[0m [1m[34mSELECT RELEASE_LOCK('3013211720225074515')[0m
|
36
36
|
[1m[35m (0.2ms)[0m [1m[34mSELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC[0m
|
37
|
+
[1m[36m (0.8ms)[0m [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
|
38
|
+
[1m[35m (19.5ms)[0m DROP DATABASE IF EXISTS `redirector_dummy_test`
|
39
|
+
[1m[36m (0.7ms)[0m [1mCREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`[0m
|
40
|
+
[1m[35m (1.9ms)[0m CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
|
41
|
+
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
|
42
|
+
[1m[36m (0.1ms)[0m [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
|
43
|
+
[1m[35m (0.5ms)[0m DROP DATABASE IF EXISTS `redirector_dummy_test`
|
44
|
+
[1m[36m (10.8ms)[0m [1mCREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`[0m
|
45
|
+
[1m[35m (0.4ms)[0m CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
|
46
|
+
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
|
47
|
+
[1m[36m (0.1ms)[0m [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
|
48
|
+
[1m[35m (0.5ms)[0m DROP DATABASE IF EXISTS `redirector_dummy_test`
|
49
|
+
[1m[36m (0.3ms)[0m [1mCREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`[0m
|
50
|
+
[1m[35m (0.4ms)[0m CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
|
51
|
+
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
|
52
|
+
[1m[36m (0.2ms)[0m [1mSELECT `schema_migrations`.`version` FROM `schema_migrations` [0m
|
53
|
+
[1m[35m (10.7ms)[0m DROP DATABASE IF EXISTS `redirector_dummy_test`
|
54
|
+
[1m[36m (6.6ms)[0m [1mCREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`[0m
|
55
|
+
[1m[35m (0.4ms)[0m CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
|
56
|
+
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `redirect_rules` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `source` varchar(255) NOT NULL, `source_is_regex` tinyint(1) DEFAULT 0 NOT NULL, `source_is_case_sensitive` tinyint(1) DEFAULT 0 NOT NULL, `destination` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 0, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
|
@@ -39,7 +39,7 @@ describe RedirectRule do
|
|
39
39
|
|
40
40
|
describe 'strip_source_whitespace before_save callback' do
|
41
41
|
it 'strips leading and trailing whitespace when saved' do
|
42
|
-
subject =
|
42
|
+
subject = build(:redirect_rule, :source => ' /needs-stripping ')
|
43
43
|
|
44
44
|
subject.save
|
45
45
|
expect(subject.reload.source).to eq('/needs-stripping')
|
@@ -21,14 +21,15 @@ describe RequestEnvironmentRule do
|
|
21
21
|
|
22
22
|
it 'should not allow an invalid regex' do
|
23
23
|
rule = build(:request_environment_rule_regex, :environment_value => '[')
|
24
|
+
|
24
25
|
rule.validate
|
25
26
|
expect(rule.errors[:environment_value]).to eq(['is an invalid regular expression'])
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should know if it's matched for a non-regex value" do
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
subject.matches?({'SERVER_NAME' => 'example.com'}).should be_truthy
|
31
|
+
subject.matches?({'HTTP_HOST' => 'www.example.com'}).should be_falsey
|
32
|
+
subject.matches?({'SERVER_NAME' => 'example.ca'}).should be_falsey
|
32
33
|
end
|
33
34
|
|
34
35
|
context 'with a case sensitive regex value' do
|
data/spec/spec_helper.rb
CHANGED
@@ -25,7 +25,7 @@ RSpec.configure do |config|
|
|
25
25
|
config.infer_base_class_for_anonymous_controllers = false
|
26
26
|
|
27
27
|
config.after(:each, :type => :feature) do
|
28
|
-
DatabaseCleaner.
|
28
|
+
DatabaseCleaner.clean_with :truncation, except: %w(ar_internal_metadata)
|
29
29
|
Capybara.reset_sessions! # Forget the (simulated) browser state
|
30
30
|
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Landau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: shoulda-matchers
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|