redirector 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48575a6f084332c0f16720d2398e8674fced3f96add66675947fc820c47070bc
4
- data.tar.gz: 1a4e1e61f2abdcc1d39c655e0d155e707769738b380408a942447bc79bc60feb
3
+ metadata.gz: 3795c5f05e3924521efe95b4fae87fb6f54ff8175cd42f57270923135e3eddc8
4
+ data.tar.gz: 8782cb91c17c0e50aef45016a99d413db0bd8543705c14123a4c59806834c8c4
5
5
  SHA512:
6
- metadata.gz: a4b89eaeb9e03e7ff035ce0233285f44107545f301c5807765cf9076e6af17de6c8fd1eeadae130584c9c965a2853e152eeae307cebb337250f56d6a9d94a374
7
- data.tar.gz: 3d693e87e63e0b554fba58be2eeb5d5bc7990eaa4a6dd3f3451b6a3d30787c73a633286008143825b27c03e5490e2d8b911a808ee0c28c3edef6151ea517855b
6
+ metadata.gz: bcadbff5bc278f14d9496838ee1069d4383bde0a75cd8a1fec00b9837e097c0c8f05449a997619a77647d5d17bf5fc10b81e9563d2aa419ac6b7d56eb2b8b9c7
7
+ data.tar.gz: e416e72e42dfcdb817a620cdbdc9ca64a9d37fcbe3a274562f99f4e0122e7b72878e2081748046825d66e80d3544cac9c13ad7560fcf8f5e383d3c6df84a6cc7
@@ -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
- validates :active, :inclusion => { :in => ['0', '1', true, false] }
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
@@ -1,3 +1,3 @@
1
1
  module Redirector
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
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'
@@ -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 to check this file into your version control system.
12
+ # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120823163756) do
14
+ ActiveRecord::Schema.define(version: 20120823163756) do
15
15
 
16
- create_table "redirect_rules", :force => true do |t|
17
- t.string "source", :null => false
18
- t.boolean "source_is_regex", :default => false, :null => false
19
- t.boolean "source_is_case_sensitive", :default => false, :null => false
20
- t.string "destination", :null => false
21
- t.boolean "active", :default => false
22
- t.datetime "created_at", :null => false
23
- t.datetime "updated_at", :null => false
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"], :name => "index_redirect_rules_on_active"
27
- add_index "redirect_rules", ["source"], :name => "index_redirect_rules_on_source"
28
- add_index "redirect_rules", ["source_is_case_sensitive"], :name => "index_redirect_rules_on_source_is_case_sensitive"
29
- add_index "redirect_rules", ["source_is_regex"], :name => "index_redirect_rules_on_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", :force => true do |t|
32
- t.integer "redirect_rule_id", :null => false
33
- t.string "environment_key_name", :null => false
34
- t.string "environment_value", :null => false
35
- t.boolean "environment_value_is_regex", :default => false, :null => false
36
- t.boolean "environment_value_is_case_sensitive", :default => true, :null => false
37
- t.datetime "created_at", :null => false
38
- t.datetime "updated_at", :null => false
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"], :name => "index_request_environment_rules_on_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
   (0.2ms) COMMIT
35
35
   (0.1ms) SELECT RELEASE_LOCK('3013211720225074515')
36
36
   (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
37
+  (0.8ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` 
38
+  (19.5ms) DROP DATABASE IF EXISTS `redirector_dummy_test`
39
+  (0.7ms) CREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
40
+  (1.9ms) 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
+  (0.1ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` 
43
+  (0.5ms) DROP DATABASE IF EXISTS `redirector_dummy_test`
44
+  (10.8ms) CREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
45
+  (0.4ms) 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
+  (0.1ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` 
48
+  (0.5ms) DROP DATABASE IF EXISTS `redirector_dummy_test`
49
+  (0.3ms) CREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
50
+  (0.4ms) 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
+  (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` 
53
+  (10.7ms) DROP DATABASE IF EXISTS `redirector_dummy_test`
54
+  (6.6ms) CREATE DATABASE `redirector_dummy_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
55
+  (0.4ms) 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 = FactoryBot.build(:redirect_rule, :source => ' /needs-stripping ')
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
- expect(subject.matches?({'SERVER_NAME' => 'example.com'})).to be_truthy
30
- expect(subject.matches?({'HTTP_HOST' => 'www.example.com'})).to be_falsey
31
- expect(subject.matches?({'SERVER_NAME' => 'example.ca'})).to be_falsey
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.clean # Truncate the database
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.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-09-14 00:00:00.000000000 Z
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