tarquinn 0.0.1 → 0.0.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
  SHA1:
3
- metadata.gz: ecb0edee29d3f22108388751e86d64641f06e927
4
- data.tar.gz: 4502cfa609572a32c6137bd2ff2639ee90641065
3
+ metadata.gz: 127a3336f88c936432f99b747ce1fcc05a8ac383
4
+ data.tar.gz: 945174dc6e9dd2d0a53cd3c999577035df8683e9
5
5
  SHA512:
6
- metadata.gz: 1c57b6df4121b783036ff66f4bb32591e98c16c3a7e57abc997158a55d0b5d67455894c557a2a135e840aef91c6722f4732876cdd18af4e4ac5e5a3bc1f4d9e5
7
- data.tar.gz: 2ba5ac3b72a550cbd48dc45858331e69d2e944fe62cac24e703461af7dabb9be7502bc6d44a25ee7e8d14124048ca3a1fee412d6f28764e9f5fa855e91da3e75
6
+ metadata.gz: 159300d5d10e03e370861da7562adce6cb149f4b6d18923d2f0df8f19d8e69abbbdacb9a85dfec4e82bb9f21d7405d6e4e2f13500c5ec1e194cc6d57afff49f9
7
+ data.tar.gz: b1bcc793e2466dca7f3a1c4cb679912c22d930dff9b4409a17583d5e3cd10cfd6e35a7cfdb2d12c91e11c62579ab306959ca19a69fe12c0e834ada7380d63d6f
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /coverage
2
+ /pkg
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile.lock CHANGED
@@ -1,14 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tarquinn (0.0.1)
4
+ tarquinn (0.0.2)
5
+ activesupport
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ activesupport (4.2.3)
11
+ i18n (~> 0.7)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ coderay (1.1.0)
9
17
  diff-lcs (1.2.5)
10
18
  docile (1.1.5)
19
+ i18n (0.7.0)
11
20
  json (1.8.3)
21
+ method_source (0.8.2)
22
+ minitest (5.8.0)
23
+ pry (0.10.1)
24
+ coderay (~> 1.1.0)
25
+ method_source (~> 0.8.1)
26
+ slop (~> 3.4)
27
+ pry-nav (0.2.4)
28
+ pry (>= 0.9.10, < 0.11.0)
12
29
  rake (10.4.2)
13
30
  rspec (2.99.0)
14
31
  rspec-core (~> 2.99.0)
@@ -23,12 +40,18 @@ GEM
23
40
  json (~> 1.8)
24
41
  simplecov-html (~> 0.10.0)
25
42
  simplecov-html (0.10.0)
43
+ slop (3.6.0)
44
+ thread_safe (0.3.5)
45
+ tzinfo (1.2.2)
46
+ thread_safe (~> 0.1)
26
47
 
27
48
  PLATFORMS
28
49
  ruby
29
50
 
30
51
  DEPENDENCIES
31
52
  bundler (~> 1.6)
53
+ pry
54
+ pry-nav
32
55
  rake
33
56
  rspec (~> 2.14)
34
57
  simplecov
data/README.md CHANGED
@@ -0,0 +1,46 @@
1
+ Tarquinn
2
+ ========
3
+
4
+ This gem makes easier to controll generic redirection
5
+
6
+ Getting started
7
+ ---------------
8
+ 1. Add Tarquinn to your `Gemfile` and `bundle install`:
9
+
10
+ ```ruby
11
+ gem 'tarquinn'
12
+ ```
13
+
14
+ 2. Include Tarquinn to your controller or to your base controller
15
+ ```ruby
16
+ ApplicationController < ActionController::Base
17
+ include Tarquinn
18
+ end
19
+ ```
20
+
21
+ 3. Program your redirection on your controllers
22
+ ```ruby
23
+ BaseController < ApplicationController
24
+ redirection_rule :redirect_login, :loggin_needed?
25
+
26
+ private
27
+
28
+ def redirect_login
29
+ login_path
30
+ end
31
+
32
+ def loggin_needed?
33
+ user.present?
34
+ end
35
+ end
36
+
37
+ StaticController < BaseController
38
+ skip_redirection_rule :redirect_login, :is_home?
39
+
40
+ private
41
+
42
+ def is_home?
43
+ params[:action] == 'home'
44
+ end
45
+ end
46
+ ```
@@ -24,7 +24,7 @@ class Tarquinn::Handler
24
24
  end
25
25
 
26
26
  def redirect_path
27
- controller.send(config.redirect)
27
+ controller.send(redirect_method)
28
28
  end
29
29
 
30
30
  def is_redirect?
@@ -1,3 +1,3 @@
1
1
  module Tarquinn
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/tarquinn.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
1
4
  module Tarquinn
2
5
  require 'tarquinn/version'
3
6
  require 'tarquinn/handler'
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tarquinn::Builder do
4
+ describe '#build' do
5
+ let(:controller) do
6
+ double('controller')
7
+ end
8
+
9
+ it do
10
+ expect(subject.build(controller)).to be_a(Tarquinn::Engine)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tarquinn::Config do
4
+ let(:subject) { described_class.new(:redirect) }
5
+
6
+ describe '#add_redirection_rules' do
7
+ context 'when not passing a block' do
8
+ it do
9
+ expect do
10
+ subject.add_redirection_rules(:methods)
11
+ end.to change { subject.methods }
12
+ end
13
+
14
+ it do
15
+ expect do
16
+ subject.add_redirection_rules(:methods)
17
+ end.not_to change { subject.blocks }
18
+ end
19
+ end
20
+
21
+ context 'when not passing only a block' do
22
+ it do
23
+ expect do
24
+ subject.add_redirection_rules { true }
25
+ end.not_to change { subject.methods }
26
+ end
27
+
28
+ it do
29
+ expect do
30
+ subject.add_redirection_rules { true }
31
+ end.to change { subject.blocks }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tarquinn::Engine do
4
+ let(:redirection_path) { '/path' }
5
+ let(:redirection_path2) { '/path2' }
6
+ let(:controller) do
7
+ double('controller', redirect_path: redirection_path, redirect_path2: redirection_path2)
8
+ end
9
+ let(:config) { Tarquinn::Config.new(:redirect_path) }
10
+ let(:config2) { Tarquinn::Config.new(:redirect_path2) }
11
+ let(:configs) { { redirect_path: config, redirect_path2: config2 } }
12
+ let(:subject) { described_class.new configs, controller }
13
+
14
+ describe '#perform_redirect?' do
15
+ context 'when no redirection should be performed' do
16
+ before do
17
+ config.add_skip_rules { true }
18
+ config2.add_skip_rules { true }
19
+ end
20
+
21
+ it do
22
+ expect(subject.perform_redirect?).to be_falsey
23
+ end
24
+ end
25
+
26
+ context 'when all redirection is required' do
27
+ before do
28
+ config.add_redirection_rules { true }
29
+ config2.add_redirection_rules { true }
30
+ end
31
+
32
+ it do
33
+ expect(subject.perform_redirect?).to be_truthy
34
+ end
35
+ end
36
+
37
+ context 'when only one allow for redirection' do
38
+ before do
39
+ config.add_redirection_rules { true }
40
+ config2.add_skip_rules { true }
41
+ end
42
+
43
+ it do
44
+ expect(subject.perform_redirect?).to be_truthy
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#perform_redirect' do
50
+ context 'when no redirection should be performed' do
51
+ before do
52
+ config.add_skip_rules { true }
53
+ config2.add_skip_rules { true }
54
+ end
55
+
56
+ it 'redirects to the first redirection' do
57
+ expect(controller).not_to receive(:redirect_to).with(redirection_path)
58
+ subject.perform_redirect
59
+ end
60
+ end
61
+
62
+ context 'when all redirection is required' do
63
+ before do
64
+ config.add_redirection_rules { true }
65
+ config2.add_redirection_rules { true }
66
+ end
67
+
68
+ it do
69
+ expect(controller).to receive(:redirect_to)
70
+ subject.perform_redirect
71
+ end
72
+ end
73
+
74
+ context 'when only one allow for redirection' do
75
+ context 'when its the first redirection' do
76
+ before do
77
+ config.add_redirection_rules { true }
78
+ config2.add_skip_rules { true }
79
+ end
80
+
81
+ it do
82
+ expect(controller).to receive(:redirect_to).with(redirection_path)
83
+ subject.perform_redirect
84
+ end
85
+ end
86
+
87
+ context 'when its the second redirection' do
88
+ before do
89
+ config.add_skip_rules { true }
90
+ config2.add_redirection_rules { true }
91
+ end
92
+
93
+ it do
94
+ expect(controller).to receive(:redirect_to).with(redirection_path2)
95
+ subject.perform_redirect
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tarquinn::Handler do
4
+ let(:redirection_path) { '/path' }
5
+ let(:controller) { double('controller', true: true, false: false, redirect_path: redirection_path) }
6
+ let(:config) { Tarquinn::Config.new(:redirect_path) }
7
+ let(:subject) { described_class.new config, controller }
8
+
9
+ describe '#perform_redirect?' do
10
+ context 'when rules allow for redirection' do
11
+ before do
12
+ config.add_redirection_rules { true }
13
+ end
14
+
15
+ it do
16
+ expect(subject.perform_redirect?).to be_truthy
17
+ end
18
+
19
+ context 'but some grant a skip' do
20
+ before do
21
+ config.add_skip_rules { true }
22
+ end
23
+
24
+ it do
25
+ expect(subject.perform_redirect?).to be_falsey
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'when rules do not allow for redirection' do
31
+ before do
32
+ config.add_redirection_rules { false }
33
+ end
34
+
35
+ it do
36
+ expect(subject.perform_redirect?).to be_falsey
37
+ end
38
+
39
+ context 'but some do not grant a skip' do
40
+ before do
41
+ config.add_skip_rules { false }
42
+ end
43
+
44
+ it do
45
+ expect(subject.perform_redirect?).to be_falsey
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when passing a method name for evaluation' do
51
+ context 'when method returns true' do
52
+ before do
53
+ config.add_redirection_rules :true
54
+ end
55
+
56
+ it do
57
+ expect(subject.perform_redirect?).to be_truthy
58
+ end
59
+
60
+ context 'but some grant a skip' do
61
+ before do
62
+ config.add_skip_rules :true
63
+ end
64
+
65
+ it do
66
+ expect(subject.perform_redirect?).to be_falsey
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'when method returns false' do
72
+ before do
73
+ config.add_redirection_rules :false
74
+ end
75
+
76
+ it do
77
+ expect(subject.perform_redirect?).to be_falsey
78
+ end
79
+
80
+ context 'but some do not grant a skip' do
81
+ before do
82
+ config.add_skip_rules :false
83
+ end
84
+
85
+ it do
86
+ expect(subject.perform_redirect?).to be_falsey
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '#redirect' do
93
+ it do
94
+ expect(controller).to receive(:redirect_to).with(redirection_path)
95
+ subject.redirect
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tarquinn do
4
+ let(:controller) { Tarquinn::Controller.new }
5
+
6
+ describe 'redirection' do
7
+ context 'when configuration calls for a method that allows redirection' do
8
+ it 'redirects to redirection path given by the method' do
9
+ expect(controller).to receive(:redirect_to).with('/path')
10
+ controller.parse_request
11
+ end
12
+ end
13
+
14
+ context 'when redirection skip method returns true' do
15
+ before do
16
+ allow(controller).to receive(:should_skip_redirect?) { true }
17
+ end
18
+
19
+ it 'does not redirect to redirection path given by the method' do
20
+ expect(controller).not_to receive(:redirect_to)
21
+ controller.parse_request
22
+ end
23
+ end
24
+ end
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,13 @@
1
1
  require 'simplecov'
2
- SimpleCov.start
2
+
3
+ SimpleCov.profiles.define 'gem' do
4
+ add_filter '/spec/'
5
+ end
6
+
7
+ SimpleCov.start 'gem'
3
8
 
4
9
  require 'tarquinn'
10
+ require 'pry-nav'
5
11
 
6
12
  support_files = File.expand_path("spec/support/**/*.rb")
7
13
  Dir[support_files].each { |file| require file }
@@ -0,0 +1,30 @@
1
+ class Tarquinn::Controller
2
+ def self.before_action(_)
3
+ end
4
+
5
+ include Tarquinn
6
+
7
+ redirection_rule :redirection_path, :should_redirect?
8
+ skip_redirection_rule :redirection_path, :should_skip_redirect?
9
+
10
+ def parse_request
11
+ perform_redirection
12
+ end
13
+
14
+ private
15
+
16
+ def redirection_path
17
+ '/path'
18
+ end
19
+
20
+ def redirect_to(_)
21
+ end
22
+
23
+ def should_redirect?
24
+ true
25
+ end
26
+
27
+ def should_skip_redirect?
28
+ false
29
+ end
30
+ end
data/tarquinn.gemspec CHANGED
@@ -17,8 +17,12 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
+ gem.add_runtime_dependency 'activesupport'
21
+
20
22
  gem.add_development_dependency "bundler", "~> 1.6"
21
23
  gem.add_development_dependency "rake"
22
24
  gem.add_development_dependency "rspec", "~> 2.14"
23
25
  gem.add_development_dependency 'simplecov'
26
+ gem.add_development_dependency 'pry'
27
+ gem.add_development_dependency 'pry-nav'
24
28
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarquinn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
11
+ date: 2015-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,34 @@ dependencies:
66
80
  - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  description: Gem for easy redirection controll
70
112
  email:
71
113
  - darthjee@gmail.com
@@ -73,6 +115,8 @@ executables: []
73
115
  extensions: []
74
116
  extra_rdoc_files: []
75
117
  files:
118
+ - .gitignore
119
+ - .rspec
76
120
  - Gemfile
77
121
  - Gemfile.lock
78
122
  - LICENSE
@@ -86,7 +130,13 @@ files:
86
130
  - lib/tarquinn/engine.rb
87
131
  - lib/tarquinn/handler.rb
88
132
  - lib/tarquinn/version.rb
133
+ - spec/lib/tarquinn/builder_spec.rb
134
+ - spec/lib/tarquinn/config_spec.rb
135
+ - spec/lib/tarquinn/engine_spec.rb
136
+ - spec/lib/tarquinn/handler_spec.rb
137
+ - spec/lib/tarquinn_spec.rb
89
138
  - spec/spec_helper.rb
139
+ - spec/support/models/tarquinn/controller.rb
90
140
  - tarquinn.gemspec
91
141
  homepage: https://github.com/darthje/tarquinn
92
142
  licenses: []