beespew 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +15 -1
- data/app/assets/stylesheets/beespew/beespew.css +8 -0
- data/config/locales/de.yml +3 -0
- data/lib/beespew/engine.rb +5 -0
- data/lib/beespew/form_builder.rb +19 -0
- data/lib/beespew/version.rb +1 -1
- data/lib/beespew.rb +6 -0
- data/spec/beespew_spec.rb +9 -1
- data/spec/dummy/app/assets/stylesheets/application.css +1 -0
- data/spec/dummy/app/controllers/support_requests_controller.rb +21 -0
- data/spec/dummy/app/models/support_request.rb +5 -0
- data/spec/dummy/app/views/support_requests/new.html.erb +27 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/locales/de.yml +2 -0
- data/spec/dummy/config/routes.rb +2 -52
- data/spec/dummy/db/migrate/20141208164522_create_support_requests.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/form_helper_spec.rb +76 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5270813ca79bb6eb252460705ee6c1ff677261
|
4
|
+
data.tar.gz: 0d25efbbeaeb2a33c98f5d6b8bc7d78e541602b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0be21555222274055af659424d17de19d2bda8d03b7a07d660bfa41dff8206a96397357d80f444105d79671f1e2f62385dc85f005a98e8fbe602d7715361043e
|
7
|
+
data.tar.gz: 43bd786e38c75709b749912191cb81aad985fcbe75177bffadca10d4a2c6a948f8b32bdce00e8dcbfab7819fc2e55d33b3bdd458bdceec294eb34dac6321163a
|
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1.5
|
5
|
+
cache: bundler
|
6
|
+
script:
|
7
|
+
- bundle exec rspec spec
|
8
|
+
notifications:
|
9
|
+
webhooks:
|
10
|
+
secure: PZ9zkk1aar0shHE87JpIE9+OgjTgYFoiK0cP+jNcuF/GjhVaypkaieKzCRldERkkz2YEi2eIqgKhybQpYAcG4q1vhpjiBpOOdLYmTsRFCSoDwt8fAlC9JRI3+D6nc4hF1y8ds9aVoYQVfCcGasIOH4KAKMbKGviPgyFIhdbIbDw=
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Beespew
|
1
|
+
# Beespew [![Build Status](https://travis-ci.org/Absolventa/beespew.svg?branch=master)](https://travis-ci.org/Absolventa/beespew)
|
2
2
|
|
3
3
|
**Beespew** is a lightweight spam protection plugin for Rails 4 using
|
4
4
|
honeypot input fields. Beespew … honeypot … get it? :wink:
|
@@ -40,6 +40,13 @@ Add a text field to your form:
|
|
40
40
|
f.text_field :beespew, placeholder: "If you are a human, leave this blank", class: 'beespew'
|
41
41
|
end
|
42
42
|
|
43
|
+
Alternatively, you can use Beespew's form helper:
|
44
|
+
|
45
|
+
form_for :comment, builder: Beespew::FormBuilder do |f|
|
46
|
+
# ...
|
47
|
+
f.honeypot, placeholder: "If you are a human, leave this blank"
|
48
|
+
end
|
49
|
+
|
43
50
|
**Note**: Don't use `hidden_field` as bots are "smart" enough to leave those untouched.
|
44
51
|
Use CSS to hide it for human users and avoid `display:none` and
|
45
52
|
`visibility:hidden` here as well.
|
@@ -85,5 +92,12 @@ strong parameters will unwillingly disable your spam protection.
|
|
85
92
|
|
86
93
|
## Changelog
|
87
94
|
|
95
|
+
### HEAD (not released yet)
|
96
|
+
|
97
|
+
### 0.2.0
|
98
|
+
* Add Beespew form builder with `honeypot` field
|
99
|
+
* Make Beespew.attribute configurable ([#1](https://github.com/Absolventa/beespew/issues/1))
|
100
|
+
* Add a default hidden style for honeypot field ([#3](https://github.com/Absolventa/beespew/issues/3))
|
101
|
+
|
88
102
|
### 0.1.0
|
89
103
|
* Initial working version
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Beespew
|
2
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
+
|
4
|
+
def beespew_field(options = {})
|
5
|
+
options = { class: 'beespew', placeholder: placeholder }.
|
6
|
+
merge(options.with_indifferent_access)
|
7
|
+
text_field Beespew.attribute, options
|
8
|
+
end
|
9
|
+
|
10
|
+
alias honeypot beespew_field
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def placeholder
|
15
|
+
I18n.t "beespew.placeholder", default: 'If you are human, leave this blank'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/beespew/version.rb
CHANGED
data/lib/beespew.rb
CHANGED
data/spec/beespew_spec.rb
CHANGED
@@ -3,7 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Beespew do
|
4
4
|
|
5
5
|
describe '.attribute' do
|
6
|
-
it
|
6
|
+
it 'defaults to "beespew"' do
|
7
|
+
expect(Beespew.attribute).to eql 'beespew'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.configure' do
|
12
|
+
it 'yields itself' do
|
13
|
+
expect { |b| Beespew.configure(&b) }.to yield_with_args(Beespew)
|
14
|
+
end
|
7
15
|
end
|
8
16
|
|
9
17
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class SupportRequestsController < ApplicationController
|
2
|
+
|
3
|
+
def new
|
4
|
+
@support_request = SupportRequest.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
@support_request = SupportRequest.new(support_request_params)
|
9
|
+
if @support_request.save
|
10
|
+
redirect_to new_support_request_path, notice: 'Support Request created.'
|
11
|
+
else
|
12
|
+
render :new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def support_request_params
|
19
|
+
params.require(:support_request).permit(:message, :subject, :beespew)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<%= form_for @support_request, builder: Beespew::FormBuilder do |f| %>
|
2
|
+
|
3
|
+
<% unless @support_request.valid? %>
|
4
|
+
<ul>
|
5
|
+
<% @support_request.errors.full_messages.each do |err| %>
|
6
|
+
<li><%= err %></li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<%= f.label :subject %><br>
|
13
|
+
<%= f.text_field :subject %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<%= f.label :message %><br>
|
18
|
+
<%= f.text_area :message %>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<%= f.honeypot %>
|
22
|
+
|
23
|
+
<p>
|
24
|
+
<%= f.submit %>
|
25
|
+
</p>
|
26
|
+
|
27
|
+
<% end %>
|
@@ -5,7 +5,7 @@ require "active_record/railtie"
|
|
5
5
|
require "action_controller/railtie"
|
6
6
|
require "action_mailer/railtie"
|
7
7
|
require "action_view/railtie"
|
8
|
-
|
8
|
+
require "sprockets/railtie"
|
9
9
|
# require "rails/test_unit/railtie"
|
10
10
|
|
11
11
|
Bundler.require(*Rails.groups)
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,56 +1,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
#
|
3
|
-
# See how all your routes lay out with "rake routes".
|
2
|
+
root 'support_requests#new'
|
4
3
|
|
5
|
-
|
6
|
-
# root 'welcome#index'
|
4
|
+
resources :support_requests
|
7
5
|
|
8
|
-
# Example of regular route:
|
9
|
-
# get 'products/:id' => 'catalog#view'
|
10
|
-
|
11
|
-
# Example of named route that can be invoked with purchase_url(id: product.id)
|
12
|
-
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
13
|
-
|
14
|
-
# Example resource route (maps HTTP verbs to controller actions automatically):
|
15
|
-
# resources :products
|
16
|
-
|
17
|
-
# Example resource route with options:
|
18
|
-
# resources :products do
|
19
|
-
# member do
|
20
|
-
# get 'short'
|
21
|
-
# post 'toggle'
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# collection do
|
25
|
-
# get 'sold'
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
|
29
|
-
# Example resource route with sub-resources:
|
30
|
-
# resources :products do
|
31
|
-
# resources :comments, :sales
|
32
|
-
# resource :seller
|
33
|
-
# end
|
34
|
-
|
35
|
-
# Example resource route with more complex sub-resources:
|
36
|
-
# resources :products do
|
37
|
-
# resources :comments
|
38
|
-
# resources :sales do
|
39
|
-
# get 'recent', on: :collection
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
|
43
|
-
# Example resource route with concerns:
|
44
|
-
# concern :toggleable do
|
45
|
-
# post 'toggle'
|
46
|
-
# end
|
47
|
-
# resources :posts, concerns: :toggleable
|
48
|
-
# resources :photos, concerns: :toggleable
|
49
|
-
|
50
|
-
# Example resource route within a namespace:
|
51
|
-
# namespace :admin do
|
52
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
53
|
-
# # (app/controllers/admin/products_controller.rb)
|
54
|
-
# resources :products
|
55
|
-
# end
|
56
6
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20141208164522) do
|
15
|
+
|
16
|
+
create_table "support_requests", force: true do |t|
|
17
|
+
t.string "subject"
|
18
|
+
t.string "message"
|
19
|
+
t.datetime "created_at"
|
20
|
+
t.datetime "updated_at"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
describe Beespew::FormBuilder do
|
2
|
+
let(:the_hive) { active_model.new }
|
3
|
+
|
4
|
+
subject { described_class.new :hive, the_hive, template, {} }
|
5
|
+
|
6
|
+
describe '#beespew_field' do
|
7
|
+
it 'returns a text field with a default css class' do
|
8
|
+
input = subject.beespew_field
|
9
|
+
|
10
|
+
expected = '<input class="beespew" id="hive_beespew" name="hive[beespew]" '
|
11
|
+
expect(input).to start_with expected
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a text field with a custom css class' do
|
15
|
+
input = subject.beespew_field class: 'foobar'
|
16
|
+
|
17
|
+
expected = '<input class="foobar" id="hive_beespew" name="hive[beespew]" '
|
18
|
+
expect(input).to start_with expected
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'obeyes the configured Beespew.attribute' do
|
22
|
+
allow(Beespew).to receive(:attribute).and_return('sweetsformysweet')
|
23
|
+
input = subject.beespew_field
|
24
|
+
|
25
|
+
expected = '<input class="beespew" id="hive_sweetsformysweet" name="hive[sweetsformysweet]"'
|
26
|
+
expect(input).to start_with expected
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with placeholder' do
|
30
|
+
it 'returns an English text by default' do
|
31
|
+
text = "If you are human, leave this blank"
|
32
|
+
expect(subject.beespew_field).to match "placeholder=\"#{text}\""
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'overrides the placeholder' do
|
36
|
+
input = subject.beespew_field placeholder: 'Leave this shizzle'
|
37
|
+
expect(input).to match "placeholder=\"Leave this shizzle\""
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with internationalization' do
|
41
|
+
before { I18n.locale = :de }
|
42
|
+
after { I18n.locale = :en }
|
43
|
+
|
44
|
+
it 'uses a translated string' do
|
45
|
+
text = "Dieses Feld bitte nicht beschriften"
|
46
|
+
expect(subject.beespew_field).to match "placeholder=\"#{text}\""
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#honeypot' do
|
54
|
+
it 'is an alias for #beespew_field' do
|
55
|
+
args = { hello: 'world' }
|
56
|
+
expected = subject.beespew_field(args)
|
57
|
+
expect(subject.honeypot(args)).to eql expected
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def active_model
|
62
|
+
@klass ||= Class.new do
|
63
|
+
include ActiveModel::Model
|
64
|
+
include Beespew::Model
|
65
|
+
attr_accessor :drones, :queen
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def template
|
70
|
+
@template ||= begin
|
71
|
+
template = Object.new
|
72
|
+
template.extend ActionView::Helpers::FormHelper
|
73
|
+
template.extend ActionView::Helpers::FormOptionsHelper
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beespew
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Zimmermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -69,12 +69,17 @@ files:
|
|
69
69
|
- .rspec
|
70
70
|
- .ruby-gemset
|
71
71
|
- .ruby-version
|
72
|
+
- .travis.yml
|
72
73
|
- Gemfile
|
73
74
|
- MIT-LICENSE
|
74
75
|
- README.md
|
75
76
|
- Rakefile
|
77
|
+
- app/assets/stylesheets/beespew/beespew.css
|
76
78
|
- beespew.gemspec
|
79
|
+
- config/locales/de.yml
|
77
80
|
- lib/beespew.rb
|
81
|
+
- lib/beespew/engine.rb
|
82
|
+
- lib/beespew/form_builder.rb
|
78
83
|
- lib/beespew/model.rb
|
79
84
|
- lib/beespew/version.rb
|
80
85
|
- spec/beespew_spec.rb
|
@@ -85,11 +90,14 @@ files:
|
|
85
90
|
- spec/dummy/app/assets/stylesheets/application.css
|
86
91
|
- spec/dummy/app/controllers/application_controller.rb
|
87
92
|
- spec/dummy/app/controllers/concerns/.keep
|
93
|
+
- spec/dummy/app/controllers/support_requests_controller.rb
|
88
94
|
- spec/dummy/app/helpers/application_helper.rb
|
89
95
|
- spec/dummy/app/mailers/.keep
|
90
96
|
- spec/dummy/app/models/.keep
|
91
97
|
- spec/dummy/app/models/concerns/.keep
|
98
|
+
- spec/dummy/app/models/support_request.rb
|
92
99
|
- spec/dummy/app/views/layouts/application.html.erb
|
100
|
+
- spec/dummy/app/views/support_requests/new.html.erb
|
93
101
|
- spec/dummy/bin/bundle
|
94
102
|
- spec/dummy/bin/rails
|
95
103
|
- spec/dummy/bin/rake
|
@@ -108,15 +116,19 @@ files:
|
|
108
116
|
- spec/dummy/config/initializers/mime_types.rb
|
109
117
|
- spec/dummy/config/initializers/session_store.rb
|
110
118
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
119
|
+
- spec/dummy/config/locales/de.yml
|
111
120
|
- spec/dummy/config/locales/en.yml
|
112
121
|
- spec/dummy/config/routes.rb
|
113
122
|
- spec/dummy/config/secrets.yml
|
123
|
+
- spec/dummy/db/migrate/20141208164522_create_support_requests.rb
|
124
|
+
- spec/dummy/db/schema.rb
|
114
125
|
- spec/dummy/lib/assets/.keep
|
115
126
|
- spec/dummy/log/.keep
|
116
127
|
- spec/dummy/public/404.html
|
117
128
|
- spec/dummy/public/422.html
|
118
129
|
- spec/dummy/public/500.html
|
119
130
|
- spec/dummy/public/favicon.ico
|
131
|
+
- spec/form_helper_spec.rb
|
120
132
|
- spec/model_spec.rb
|
121
133
|
- spec/spec_helper.rb
|
122
134
|
homepage: https://github.com/Absolventa/beespew
|
@@ -152,11 +164,14 @@ test_files:
|
|
152
164
|
- spec/dummy/app/assets/stylesheets/application.css
|
153
165
|
- spec/dummy/app/controllers/application_controller.rb
|
154
166
|
- spec/dummy/app/controllers/concerns/.keep
|
167
|
+
- spec/dummy/app/controllers/support_requests_controller.rb
|
155
168
|
- spec/dummy/app/helpers/application_helper.rb
|
156
169
|
- spec/dummy/app/mailers/.keep
|
157
170
|
- spec/dummy/app/models/.keep
|
158
171
|
- spec/dummy/app/models/concerns/.keep
|
172
|
+
- spec/dummy/app/models/support_request.rb
|
159
173
|
- spec/dummy/app/views/layouts/application.html.erb
|
174
|
+
- spec/dummy/app/views/support_requests/new.html.erb
|
160
175
|
- spec/dummy/bin/bundle
|
161
176
|
- spec/dummy/bin/rails
|
162
177
|
- spec/dummy/bin/rake
|
@@ -175,14 +190,18 @@ test_files:
|
|
175
190
|
- spec/dummy/config/initializers/mime_types.rb
|
176
191
|
- spec/dummy/config/initializers/session_store.rb
|
177
192
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
193
|
+
- spec/dummy/config/locales/de.yml
|
178
194
|
- spec/dummy/config/locales/en.yml
|
179
195
|
- spec/dummy/config/routes.rb
|
180
196
|
- spec/dummy/config/secrets.yml
|
197
|
+
- spec/dummy/db/migrate/20141208164522_create_support_requests.rb
|
198
|
+
- spec/dummy/db/schema.rb
|
181
199
|
- spec/dummy/lib/assets/.keep
|
182
200
|
- spec/dummy/log/.keep
|
183
201
|
- spec/dummy/public/404.html
|
184
202
|
- spec/dummy/public/422.html
|
185
203
|
- spec/dummy/public/500.html
|
186
204
|
- spec/dummy/public/favicon.ico
|
205
|
+
- spec/form_helper_spec.rb
|
187
206
|
- spec/model_spec.rb
|
188
207
|
- spec/spec_helper.rb
|