kandr-easy_captcha 0.8.0 → 0.9.0

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: b4731d62f91a4a804c690b30a493cf074e34751543049631b5298ef675e1216c
4
- data.tar.gz: '055049676e7c65dedd644969e72ecf6500cfbc144e2177c8f4725b16d42eb86b'
3
+ metadata.gz: 7afea87e8b21ef3ff7055cd15b30c1d78d40d2cfde7198734e110797631c8dd4
4
+ data.tar.gz: 6436bbdf72bc8fba98f80c7cc4d85a49a576905dabaa48c2b552eacfd8e53432
5
5
  SHA512:
6
- metadata.gz: 4d8f84fa675cde65fd4ec50f213be9f869bf53a21b4c4a809f87d232a42cab9fc1b418e138d5a32d62a69fefbe3b52f53a8a0140b8025106bc23cdee76f0a855
7
- data.tar.gz: bc33b0c978c9a3ea507c12a6ec1fd86fb96fe9f4f9ee772a41a875075a60740ad81873002956d3beebfabcd96b98b84342af62192f778c2e94ff56d3770d86d4
6
+ metadata.gz: 72091d69c920aa172ba2059eb7d9408ea8f8dd2dec4fc18d2cf4acdc47fa3e7d002a89f0470e6fd7ca5f4def95103ce7f77e146dde7e7726685b603430cbd966
7
+ data.tar.gz: e54c20efbdc0b587837751e1ecdd2ab34154b00d129e45a9da55104c6ed539f1ac216d4da9d926da166ae56c0561ad9e2f71ea22d83611907febeb00d98a6029
data/README.md CHANGED
@@ -1,14 +1,22 @@
1
- = EasyCAPTCHA
1
+ # EasyCAPTCHA
2
+
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/0505012081a472de86e2/maintainability)](https://codeclimate.com/github/K-and-R/easy_captcha/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/0505012081a472de86e2/test_coverage)](https://codeclimate.com/github/K-and-R/easy_captcha/test_coverage)
2
5
 
3
6
  A simple captcha implementation for Rails 5+ based on RMagick.
4
7
 
5
- This (`kandr-easy_captcha`) is a fork of [EasyCaptcha](https://github.com/phatworx/easy_captcha) (`easy_captcha`) with Rails 5+ support. This fork is maintained by Karl Wilbur/K&R Software (karl@kandrsoftware.com).
8
+ This (`kandr-easy_captcha`) is a fork of
9
+ [EasyCaptcha](https://github.com/phatworx/easy_captcha) (`easy_captcha`) with Rails 5+ support. This fork is
10
+ maintained by Karl Wilbur/K&R Software (karl@kandrsoftware.com).
11
+
12
+ ## Dependencies/Requirements
6
13
 
7
- == Dependencies
14
+ * Rails 5+ (<http://github.com/rails/rails>)
15
+ * RMagick
8
16
 
9
17
  RMagick should be included in your `Gemfile`
10
18
 
11
- ```
19
+ ```ruby
12
20
  gem 'rmagick'
13
21
  ```
14
22
 
@@ -18,7 +26,7 @@ for Java/JRuby you can use
18
26
  gem 'rmagick4j'
19
27
  ```
20
28
 
21
- == Installation
29
+ ## Installation
22
30
 
23
31
  add to Gemfile
24
32
 
@@ -32,9 +40,10 @@ after running `bundle install`, execute
32
40
  rails g easy_captcha:install
33
41
  ```
34
42
 
35
- == Configuration
43
+ ## Configuration
36
44
 
37
- You can configure `easy_captcha` in `config/initializers/easy_captcha.rb`, if you want to customize the default configuration
45
+ You can configure `easy_captcha` in `config/initializers/easy_captcha.rb`, if
46
+ you want to customize the default configuration
38
47
 
39
48
  ```ruby
40
49
  EasyCaptcha.setup do |config|
@@ -109,9 +118,10 @@ You can configure `easy_captcha` in `config/initializers/easy_captcha.rb`, if yo
109
118
  end
110
119
  ```
111
120
 
112
- == Caching
121
+ ## Caching
113
122
 
114
- It is strongly recommended to enable caching. You can see the three paramters which you have to fill in your config file below.
123
+ It is strongly recommended to enable caching. You can see the three paramters which you have to fill in your config
124
+ file below.
115
125
 
116
126
  ```ruby
117
127
  EasyCaptcha.setup do |config|
@@ -126,12 +136,7 @@ It is strongly recommended to enable caching. You can see the three paramters wh
126
136
  end
127
137
  ```
128
138
 
129
- == Requirements
130
-
131
- * RMagick
132
- * Rails 3 (http://github.com/rails/rails)
133
-
134
- == Example
139
+ ## Example
135
140
 
136
141
  ```ruby
137
142
  <% form_tag '/' do %>
@@ -144,36 +149,28 @@ It is strongly recommended to enable caching. You can see the three paramters wh
144
149
  <% end %>
145
150
  ```
146
151
 
147
- == Example app
152
+ ## Example app
148
153
 
149
- You find an example app under: http://github.com/phatworx/easy_captcha_example
154
+ You find an example app under: <http://github.com/phatworx/easy_captcha_example>
150
155
 
151
- == History
156
+ ## History
152
157
 
153
- * 0.1 init
154
- * 0.2 cache support for high frequented sites
155
- * 0.3 use generators, optimizations, update licence to same of all my plugins
156
- * 0.4 generator support
157
- * 0.5 (transparent) background support
158
- * 0.6 espeak support for barrier-free support
158
+ See the [CHANGELOG.md](./CHANGELOG.md)
159
159
 
160
- == Maintainers
160
+ ## Maintainers
161
161
 
162
- * Team Phatworx (http://github.com/phatworx)
163
- * Marco Scholl (http://github.com/traxanos)
164
- * Alexander Dreher (http://github.com/alexdreher)
165
- * Christoph Chilian (http://github.com/cc-web)
162
+ * Karl Wilbur (<http://github.com/karlwilbur>)
163
+ * K&R Software (<http://github.com/K-and-R>)
166
164
 
167
- == Contributing to EasyCaptcha
165
+ ## Contributing to (K&R) EasyCaptcha
168
166
 
169
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
170
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
167
+ * See the [TODO.md](./TODO.md) file for a list of needed changes
171
168
  * Fork the project
172
169
  * Start a feature/bugfix branch
173
170
  * Commit and push until you are happy with your contribution
174
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
175
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
171
+ * Make sure to add tests for it!
172
+ * Please do not edit `Rakefile`, `EasyCaptcha::VERSION`, or `CHANGELOG`
176
173
 
177
- == Copyright
174
+ ## Copyright
178
175
 
179
176
  Copyright (c) 2010 Marco Scholl. See LICENSE.txt for further details.
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # require 'rails-controller-testing'
6
+ # Rails::Controller::Testing.install
7
+
8
+ require 'fixtures/application'
9
+ Rails.logger = Logger.new('/dev/null')
10
+
11
+ RSpec.describe EasyCaptcha::CaptchaController, type: :controller do
12
+ let(:controller) { described_class.new }
13
+
14
+ before do
15
+ EasyCaptcha.init
16
+ EasyCaptcha.setup do |config|
17
+ config.cache = false
18
+ config.espeak = true
19
+ end
20
+ end
21
+
22
+ describe '`captcha` action' do
23
+ it 'exists' do
24
+ expect(controller).to respond_to :captcha
25
+ end
26
+
27
+ context 'with defaults' do
28
+ before do
29
+ get :captcha
30
+ end
31
+
32
+ it 'sends an image' do
33
+ expect(response.header['Content-Type']).to eq 'image/png'
34
+ end
35
+
36
+ it 'sends content' do
37
+ expect(response.body).not_to be_empty
38
+ end
39
+ end
40
+
41
+ context 'with a WAV request' do
42
+ before do
43
+ get :captcha, format: 'wav'
44
+ end
45
+
46
+ it 'sends an audio file' do
47
+ expect(response.header['Content-Type']).to eq 'audio/wav'
48
+ end
49
+
50
+ it 'sends content' do
51
+ expect(response.body).not_to be_empty
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe EasyCaptcha::Captcha do
6
+ let(:captcha_text) { 'asdf246' }
7
+ let(:captcha) { described_class.new(captcha_text) }
8
+
9
+ before do
10
+ EasyCaptcha.setup
11
+ end
12
+
13
+ it 'uses new CAPTCHA text passed on initialization' do
14
+ expect(captcha.code).to eq captcha_text
15
+ end
16
+
17
+ it 'generates a CAPTCHA on initialization' do
18
+ expect(captcha.image).not_to be_nil
19
+ end
20
+
21
+ it 'shows its class name when inspected' do
22
+ expect(captcha.inspect).to include described_class.name
23
+ end
24
+
25
+ it 'shows its code value when inspected' do
26
+ expect(captcha.inspect).to include "@code=#{captcha_text}"
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'fixtures/application'
5
+ require 'fixtures/controller'
6
+
7
+ RSpec.describe 'EasyCaptcha::ControllerHelpers', type: :helper do
8
+ let(:controller) { EasyCaptcha::TestController.new }
9
+
10
+ before do
11
+ EasyCaptcha.setup
12
+ end
13
+
14
+ it 'has a `valid_captcha?` method' do
15
+ expect(helper).to respond_to :valid_captcha?
16
+ end
17
+
18
+ it 'has a `captcha_valid?` method' do
19
+ expect(helper).to respond_to :captcha_valid?
20
+ end
21
+ end
@@ -1,22 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3
+ require 'spec_helper'
4
4
 
5
5
  RSpec.describe EasyCaptcha::Espeak do
6
+ before do
7
+ # Ensure that we have created a config
8
+ EasyCaptcha.setup
9
+ end
10
+
6
11
  context 'with default values' do
7
- subject(:captcha) { described_class.new }
12
+ subject(:audio_captcha) { described_class.new }
8
13
 
9
14
  let(:amplitude_range) { 80..120 }
10
15
  let(:pitch_range) { 30..70 }
11
16
 
12
- specify(:amplitude) { expect(amplitude_range).to include(captcha.amplitude) }
13
- specify(:pitch) { expect(pitch_range).to include(captcha.pitch) }
14
- specify(:gap) { expect(captcha.gap).to eq 80 }
15
- specify(:voice) { expect(captcha.voice).to be_nil }
17
+ specify(:amplitude) { expect(amplitude_range).to include(audio_captcha.amplitude) }
18
+ specify(:pitch) { expect(pitch_range).to include(audio_captcha.pitch) }
19
+ specify(:gap) { expect(audio_captcha.gap).to eq 80 }
20
+ specify(:voice) { expect(audio_captcha.voice).to be_nil }
21
+
22
+ context 'when generating WAV file' do
23
+ let(:code) { 'asdf2648' }
24
+ let(:wav_file) { Tempfile.new("#{code}.wav") }
25
+
26
+ after do
27
+ wav_file.close!
28
+ wav_file.unlink
29
+ end
30
+
31
+ it 'generates without error' do
32
+ expect { audio_captcha.generate(code, wav_file.path) }.not_to raise_error
33
+ end
34
+
35
+ it 'generates file content' do
36
+ audio_captcha.generate(code, wav_file.path)
37
+ expect(wav_file.size).not_to be_zero
38
+ end
39
+
40
+ it 'raises an ArgumentError with an invalid code' do
41
+ expect { audio_captcha.generate(nil, wav_file.path) }.to raise_error ArgumentError
42
+ end
43
+
44
+ context 'with an `EasyCaptcha::Captcha` instance as its code' do
45
+ let(:captcha_code_object) { EasyCaptcha::Captcha.new(code) }
46
+
47
+ it 'can accept code argument without an error' do
48
+ expect { audio_captcha.generate(captcha_code_object, wav_file.path) }.not_to raise_error
49
+ end
50
+
51
+ it 'can generate file content' do
52
+ audio_captcha.generate(captcha_code_object, wav_file.path)
53
+ expect(wav_file.size).not_to be_zero
54
+ end
55
+ end
56
+ end
16
57
  end
17
58
 
18
59
  context 'with config: voices' do
19
- subject(:captcha) do
60
+ subject(:audio_captcha) do
20
61
  described_class.new do |config|
21
62
  config.voice = voices
22
63
  end
@@ -24,6 +65,6 @@ RSpec.describe EasyCaptcha::Espeak do
24
65
 
25
66
  let(:voices) { ['german', 'german+m1'] }
26
67
 
27
- specify { expect(voices).to include(captcha.voice) }
68
+ specify { expect(voices).to include(audio_captcha.voice) }
28
69
  end
29
70
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'spec_helper'
5
+ require 'generator_spec'
6
+
7
+ require 'generators/easy_captcha/install_generator'
8
+
9
+ RSpec.describe EasyCaptcha::Generators::InstallGenerator, type: :generator do
10
+ temp_dir = File.expand_path('../../../tmp', __dir__)
11
+ destination temp_dir
12
+
13
+ # rubocop:disable RSpec/BeforeAfterAll
14
+ before(:all) do
15
+ prepare_destination
16
+ # Replicate a Rails app structure
17
+ FileUtils.mkdir_p "#{temp_dir}/config/initializers"
18
+ File.open "#{temp_dir}/config/routes.rb", 'w' do |f|
19
+ f.write "Rails.application.routes.draw do \nend"
20
+ end
21
+ FileUtils.mkdir_p "#{temp_dir}/app/controllers"
22
+ File.open "#{temp_dir}/app/controllers/application_controller.rb", 'w' do |f|
23
+ f.write "class ApplicationController \nend"
24
+ end
25
+ # Ensure taht `ApplicationController` is already defined.
26
+ require "#{temp_dir}/app/controllers/application_controller.rb"
27
+ run_generator
28
+ end
29
+
30
+ after(:all) do
31
+ FileUtils.rm_rf "#{temp_dir}/config"
32
+ FileUtils.rm_rf "#{temp_dir}/app"
33
+ end
34
+ # rubocop:enable RSpec/BeforeAfterAll
35
+
36
+ # rubocop:disable Lint/AmbiguousBlockAssociation
37
+ specify do
38
+ expect(destination_root).to have_structure {
39
+ directory('config') do
40
+ directory('initializers') do
41
+ file('easy_captcha.rb') do
42
+ contains('EasyCaptcha.setup')
43
+ end
44
+ end
45
+ end
46
+ }
47
+ end
48
+
49
+ specify do
50
+ expect(destination_root).to have_structure {
51
+ directory('app') do
52
+ directory('controllers') do
53
+ file('application_controller.rb') do
54
+ contains('reset_last_captcha_code!')
55
+ end
56
+ end
57
+ end
58
+ }
59
+ end
60
+
61
+ specify do
62
+ expect(destination_root).to have_structure {
63
+ directory('config') do
64
+ file('routes.rb') do
65
+ contains('captcha_route')
66
+ end
67
+ end
68
+ }
69
+ end
70
+ # rubocop:enable Lint/AmbiguousBlockAssociation
71
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'fixtures/model'
6
+
7
+ RSpec.describe EasyCaptcha::ModelHelpers, type: :helper do
8
+ let(:model) { EasyCaptcha::TestModel.new }
9
+
10
+ it 'is included in the ActiveRecord helpers' do
11
+ expect(ActiveRecord::Base).to include described_class
12
+ end
13
+
14
+ context 'when included in a model instance' do
15
+ it 'has `captcha` reader' do
16
+ expect(model).to respond_to :captcha
17
+ end
18
+
19
+ it 'has `captcha` writer' do
20
+ expect(model).to respond_to :captcha=
21
+ end
22
+
23
+ it 'has `captcha_verification` writer' do
24
+ expect(model).to respond_to :captcha_verification=
25
+ end
26
+
27
+ it 'has `captcha_valid?` method' do
28
+ expect(model).to respond_to :captcha_valid?
29
+ end
30
+
31
+ it 'has `captcha_verification_match?` method' do
32
+ expect(model).to respond_to :captcha_verification_match?
33
+ end
34
+
35
+ it 'is not valid with a `nil` CAPTCHA' do
36
+ model.captcha = nil
37
+ model.captcha_verification = nil
38
+ expect(model).not_to be_valid_captcha
39
+ end
40
+
41
+ it 'is not valid with a `nil` CAPTCHA verification text' do
42
+ model.captcha = 'foo'
43
+ model.captcha_verification = nil
44
+ expect(model).not_to be_valid_captcha
45
+ end
46
+
47
+ it 'is not valid with mismatched CAPTCHA and verification text' do
48
+ model.captcha = 'foo'
49
+ model.captcha_verification = 'bar'
50
+ expect(model).not_to be_valid_captcha
51
+ end
52
+
53
+ it 'is valid with matching CAPTCHA and verification text' do
54
+ model.captcha = 'foo'
55
+ model.captcha_verification = 'foo'
56
+ expect(model).to be_valid_captcha
57
+ end
58
+
59
+ it 'is valid with matching CAPTCHA and verification text with mismatched case' do
60
+ model.captcha = 'Foo'
61
+ model.captcha_verification = 'foo'
62
+ expect(model).to be_valid_captcha
63
+ end
64
+ end
65
+ end
@@ -1,19 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3
+ require 'spec_helper'
4
4
 
5
- module EasyCaptchaTestApp
6
- class TestApp < ::Rails::Application
7
- end
8
-
9
- TestApp.routes.draw do
10
- captcha_route
11
- end
12
- end
5
+ require 'fixtures/application'
13
6
 
14
7
  RSpec.describe EasyCaptcha::CaptchaController, type: :routing do
15
- routes { EasyCaptchaTestApp::TestApp.routes }
16
- let(:routeset) { EasyCaptchaTestApp::TestApp.routes }
8
+ routes { Rails.application.routes }
9
+ let(:routeset) { Rails.application.routes }
17
10
  let(:captcha_request) { { get: '/captcha' } }
18
11
 
19
12
  it 'has added a route' do
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe EasyCaptcha::ViewHelpers, type: :helper do
6
+ describe 'captcha_tag' do
7
+ let(:captcha_path) { '/captcha' }
8
+
9
+ it 'returns an image tag' do
10
+ allow(helper).to receive(:captcha_path).and_return(captcha_path)
11
+ expect(helper.captcha_tag).to match(%r{^<img alt="captcha" .* src="#{captcha_path}" />$})
12
+ end
13
+ end
14
+ end
@@ -1,146 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
3
+ require 'spec_helper'
4
4
 
5
5
  describe EasyCaptcha do
6
- describe '#setup' do
7
- described_class.setup do |config|
8
- # Cache
9
- config.cache = false
10
-
11
- # Chars
12
- config.captcha_character_pool = %w[2 3 4 5 6 7 9 A C D E F G H J K L M N P Q R S T U X Y Z]
13
-
14
- # Image
15
- config.captcha_image_height = 40
16
- config.captcha_image_width = 140
17
-
18
- # Length
19
- config.captcha_character_count = 6
20
-
21
- # configure generator
22
- config.generator :default do |generator|
23
- # Blur
24
- generator.blur = true
25
- generator.blur_radius = 1
26
- generator.blur_sigma = 2
27
-
28
- # Font
29
- generator.font_size = 24
30
- generator.font_fill_color = '#333333'
31
- generator.font_stroke_color = '#000000'
32
- generator.font_stroke = 0
33
- generator.font_family = File.expand_path('../resources/afont.ttf', __dir__)
34
-
35
- # Image background
36
- generator.image_background_color = '#FFFFFF'
37
-
38
- # Implode
39
- generator.implode = 0.1
6
+ it 'has a VERSION' do
7
+ expect(described_class::VERSION).not_to be_blank
8
+ end
40
9
 
41
- # Sketch
42
- generator.sketch = true
43
- generator.sketch_radius = 3
44
- generator.sketch_sigma = 1
10
+ describe '#setup' do
11
+ context 'when using defaults' do
12
+ it 'does not require a block to be given' do
13
+ expect { described_class.setup }.not_to raise_error
14
+ end
45
15
 
46
- # Wave
47
- generator.wave = true
48
- generator.wave_length = (60..100)
49
- generator.wave_amplitude = (3..5)
16
+ it 'will use defaults if no block given' do
17
+ described_class.setup
50
18
  end
51
- end
52
19
 
53
- it 'does not cache' do
54
- expect(described_class).not_to be_cache
20
+ it 'has default generator' do
21
+ expect(described_class.generator).to be_an(EasyCaptcha::Generator::Default)
22
+ end
55
23
  end
56
24
 
57
- it 'has default generator' do
58
- expect(described_class.generator).to be_an(EasyCaptcha::Generator::Default)
59
- end
25
+ context 'when chaging defaults' do
26
+ let(:captcha_config_options) do
27
+ {
28
+ cache: false,
29
+ captcha_character_pool: %w[2 4 6 8 A E I O U],
30
+ captcha_image_height: 6,
31
+ captcha_image_width: 9,
32
+ captcha_character_count: 6
33
+ }
34
+ end
60
35
 
61
- describe '#depracations' do
62
- let(:config_methods) do
63
- %i[
64
- blur
65
- blur_radius
66
- blur_sigma
67
- font_family
68
- font_fill_color
69
- font_size
70
- font_stroke
71
- font_stroke_color
72
- image_background_color
73
- implode
74
- sketch
75
- sketch_radius
76
- sketch_sigma
77
- wave
78
- wave_amplitude
79
- wave_length
80
- ]
36
+ let(:generator_config_options) do
37
+ {
38
+ blur: true,
39
+ blur_radius: 1,
40
+ blur_sigma: 2,
41
+ font_size: 24,
42
+ font_fill_color: '#333333',
43
+ font_stroke_color: '#000000',
44
+ font_stroke: 0,
45
+ font_family: File.expand_path('../resources/afont.ttf', __dir__),
46
+ image_background_color: '#FFFFFF',
47
+ implode: 0.1,
48
+ sketch: true,
49
+ sketch_radius: 3,
50
+ sketch_sigma: 1,
51
+ wave: true,
52
+ wave_length: (60..100),
53
+ wave_amplitude: (3..5)
54
+ }
81
55
  end
82
56
 
83
57
  before do
84
58
  described_class.setup do |config|
85
- # Image
86
- config.captcha_image_height = 40
87
- config.captcha_image_width = 140
88
-
89
- # Length
90
- config.captcha_character_count = 6
91
-
92
- config.generator :default do |generator|
93
- # Blur
94
- generator.blur = true
95
- generator.blur_radius = 1
96
- generator.blur_sigma = 2
97
-
98
- # Font
99
- generator.font_size = 24
100
- generator.font_fill_color = '#333333'
101
- generator.font_stroke_color = '#000000'
102
- generator.font_stroke = 0
103
- generator.font_family = File.expand_path('../resources/afont.ttf', __dir__)
104
-
105
- # Image background
106
- generator.image_background_color = '#FFFFFF'
107
-
108
- # Implode
109
- generator.implode = 0.1
110
-
111
- # Sketch
112
- generator.sketch = true
113
- generator.sketch_radius = 3
114
- generator.sketch_sigma = 1
115
-
116
- # Wave
117
- generator.wave = true
118
- generator.wave_length = (60..100)
119
- generator.wave_amplitude = (3..5)
120
- end
59
+ captcha_config_options.each { |k, v| config.send("#{k}=", v) }
60
+ config.generator(:default) { |generator| generator_config_options.each { |k, v| generator.send("#{k}=", v) } }
121
61
  end
122
62
  end
123
63
 
124
- it 'returns non-nil for config methods' do
125
- config_methods.each do |opt|
126
- expect(described_class.generator.send(opt)).not_to be_nil
127
- end
128
- end
129
-
130
- it 'raises NoMethodError on missing non-depracations' do
131
- expect { described_class.send(EasyCaptcha::DEPRECATED_METHODS.first) }.not_to raise_error(NoMethodError)
132
- end
133
-
134
- it 'does not raise NoMethodError on depracations' do
135
- expect { described_class.send(:a_missing_method) }.to raise_error(NoMethodError)
136
- end
137
-
138
- it 'does not respond_to? depracations' do
139
- expect(described_class).not_to respond_to(EasyCaptcha::DEPRECATED_METHODS.first)
140
- end
141
-
142
- it 'does not respond_to? missing non-depracations' do
143
- expect(described_class).not_to respond_to(:a_missing_method)
64
+ it 'does not cache' do
65
+ expect(described_class).not_to be_cache
144
66
  end
145
67
  end
146
68
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
+ require 'action_controller'
5
+ require 'action_dispatch'
6
+ require 'action_view'
7
+
8
+ class EasyCaptcha::TestApp < ::Rails::Application
9
+ def env_config; {} end
10
+ def routes
11
+ return @routes unless !defined?(@routes) || @routes.nil?
12
+ @routes = ActionDispatch::Routing::RouteSet.new
13
+ @routes
14
+ end
15
+ end
16
+
17
+ module Rails
18
+ def self.application
19
+ @app ||= EasyCaptcha::TestApp.new
20
+ end
21
+ end
22
+ Rails.application.routes.draw do
23
+ captcha_route
24
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.logger = Logger.new('/dev/null')
4
+ class EasyCaptcha::TestController < ActionController::Base
5
+ include ActionController::Helpers
6
+
7
+ attr_accessor :controller_path, :session
8
+
9
+ def initilaize(*args)
10
+ @session = {}
11
+ super
12
+ end
13
+
14
+ def params
15
+ {}
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EasyCaptcha::TestModel
4
+ # Required dependency for ActiveModel::Errors
5
+ extend ActiveModel::Naming
6
+
7
+ include EasyCaptcha::ModelHelpers
8
+ acts_as_easy_captcha
9
+
10
+ attr_accessor :name
11
+ attr_reader :errors
12
+
13
+ def initialize
14
+ @errors = ActiveModel::Errors.new(self)
15
+ end
16
+
17
+ # For ActiveModel::Errors, the following methods are needed to be minimally implemented
18
+ def read_attribute_for_validation(attr)
19
+ send(attr)
20
+ end
21
+
22
+ def self.human_attribute_name(attr, _options = {})
23
+ attr
24
+ end
25
+
26
+ def self.lookup_ancestors
27
+ [self]
28
+ end
29
+ end
@@ -5,8 +5,16 @@ require 'pry'
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
7
  require 'simplecov'
8
- SimpleCov.start 'rails'
8
+ # SimpleCov.minimum_coverage 90
9
+ SimpleCov.start 'rails' do
10
+ # Ignore initilalizer template
11
+ add_filter 'lib/generators/templates/'
12
+ # Ignore version file because it already loaded and won't be detected by SimpleCov
13
+ add_filter 'lib/easy_captcha/version'
14
+ end
15
+
9
16
  # require 'rails/all'
17
+ require 'active_support/all'
10
18
  require 'action_controller'
11
19
  require 'action_dispatch'
12
20
  require 'action_view'
@@ -16,3 +24,11 @@ require 'easy_captcha'
16
24
  # Requires supporting files with custom matchers and macros, etc,
17
25
  # in ./support/ and its subdirectories.
18
26
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
27
+
28
+ # RSpec.configure do |config|
29
+ # [:controller, :view, :request].each do |type|
30
+ # config.include ::Rails::Controller::Testing::TestProcess, :type => type
31
+ # config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type
32
+ # config.include ::Rails::Controller::Testing::Integration, :type => type
33
+ # end
34
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kandr-easy_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Scholl
@@ -50,9 +50,18 @@ extra_rdoc_files:
50
50
  files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
+ - spec/easy_captcha/captcha_controller_spec.rb
54
+ - spec/easy_captcha/captcha_spec.rb
55
+ - spec/easy_captcha/controller_helpers_spec.rb
53
56
  - spec/easy_captcha/espeak_spec.rb
57
+ - spec/easy_captcha/generators/install_generator_spec.rb
58
+ - spec/easy_captcha/model_helpers_spec.rb
54
59
  - spec/easy_captcha/routing_spec.rb
60
+ - spec/easy_captcha/view_helpers_spec.rb
55
61
  - spec/easy_captcha_spec.rb
62
+ - spec/fixtures/application.rb
63
+ - spec/fixtures/controller.rb
64
+ - spec/fixtures/model.rb
56
65
  - spec/spec.opts
57
66
  - spec/spec_helper.rb
58
67
  homepage: http://github.com/K-and-R/easy_captcha
@@ -79,8 +88,17 @@ signing_key:
79
88
  specification_version: 4
80
89
  summary: CAPTCHA Plugin for Rails
81
90
  test_files:
91
+ - spec/easy_captcha/captcha_controller_spec.rb
92
+ - spec/easy_captcha/captcha_spec.rb
93
+ - spec/easy_captcha/controller_helpers_spec.rb
82
94
  - spec/easy_captcha/espeak_spec.rb
95
+ - spec/easy_captcha/generators/install_generator_spec.rb
96
+ - spec/easy_captcha/model_helpers_spec.rb
83
97
  - spec/easy_captcha/routing_spec.rb
98
+ - spec/easy_captcha/view_helpers_spec.rb
84
99
  - spec/easy_captcha_spec.rb
100
+ - spec/fixtures/application.rb
101
+ - spec/fixtures/controller.rb
102
+ - spec/fixtures/model.rb
85
103
  - spec/spec.opts
86
104
  - spec/spec_helper.rb