europeana-feedback-button 0.0.5 → 0.0.6
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 +5 -5
- data/.codeclimate.yml +5 -0
- data/.rubocop.yml +2 -8
- data/.travis.yml +1 -2
- data/Gemfile +11 -6
- data/README.md +17 -7
- data/Rakefile +1 -0
- data/app/controllers/europeana/feedback_button/application_controller.rb +28 -0
- data/app/controllers/europeana/feedback_button/feedback_controller.rb +20 -12
- data/app/mailers/europeana/feedback_button/feedback_mailer.rb +9 -6
- data/app/models/europeana/feedback_button/feedback.rb +21 -0
- data/app/validators/europeana/feedback_button/word_count_validator.rb +26 -0
- data/app/views/concerns/europeana/feedback_button/feedbackable_view.rb +5 -5
- data/app/views/europeana/feedback_button/feedback_mailer/post.text.erb +2 -0
- data/bin/rails +19 -5
- data/config/routes.rb +1 -0
- data/europeana-feedback-button.gemspec +7 -10
- data/lib/europeana/feedback_button.rb +32 -1
- data/lib/europeana/feedback_button/engine.rb +2 -1
- data/lib/europeana/feedback_button/version.rb +2 -1
- data/lib/generators/europeana/feedback_button/install_generator.rb +15 -0
- data/lib/generators/europeana/feedback_button/templates/europeana_feedback_button.rb +8 -0
- data/spec/controllers/feedback_controller_spec.rb +82 -19
- data/spec/dummy/Rakefile +2 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/javascripts/application.js +2 -1
- data/spec/dummy/app/assets/stylesheets/application.css +3 -3
- data/spec/dummy/app/controllers/application_controller.rb +1 -3
- data/spec/dummy/app/controllers/welcome_controller.rb +3 -5
- data/spec/dummy/app/helpers/application_helper.rb +1 -0
- data/spec/dummy/app/jobs/application_job.rb +4 -0
- data/spec/dummy/app/mailers/application_mailer.rb +2 -1
- data/spec/dummy/app/views/layouts/application.html.erb +9 -9
- data/spec/dummy/app/views/layouts/mailer.html.erb +10 -6
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +2 -1
- data/spec/dummy/bin/rails +2 -1
- data/spec/dummy/bin/rake +1 -0
- data/spec/dummy/bin/setup +16 -16
- data/spec/dummy/bin/update +30 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/config/application.rb +12 -18
- data/spec/dummy/config/boot.rb +3 -2
- data/spec/dummy/config/environment.rb +2 -1
- data/spec/dummy/config/environments/development.rb +24 -20
- data/spec/dummy/config/environments/production.rb +22 -26
- data/spec/dummy/config/environments/test.rb +10 -6
- data/spec/dummy/config/initializers/application_controller_renderer.rb +9 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/europeana_feedback_button.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +1 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -6
- data/spec/dummy/config/locales/en.yml +10 -0
- data/spec/dummy/config/puma.rb +36 -0
- data/spec/dummy/config/routes.rb +2 -57
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +6 -6
- data/spec/dummy/public/422.html +6 -6
- data/spec/dummy/public/500.html +6 -6
- data/{app/assets/images/europeana_feedback_button/.keep → spec/dummy/public/apple-touch-icon-precomposed.png} +0 -0
- data/{app/models/.keep → spec/dummy/public/apple-touch-icon.png} +0 -0
- data/spec/lib/europeana/feedback_button_spec.rb +21 -0
- data/spec/mailers/feedback_mailer_spec.rb +54 -0
- data/spec/models/feedback_spec.rb +25 -0
- data/spec/spec_helper.rb +11 -1
- metadata +52 -53
- data/QUICKSTART.md +0 -30
- data/app/assets/javascripts/europeana_feedback_button/application.js +0 -13
- data/app/assets/stylesheets/europeana_feedback_button/application.css +0 -15
- data/app/helpers/europeana/feedback_button/application_helper.rb +0 -7
- data/app/helpers/europeana/feedback_button/feedback_helper.rb +0 -12
- data/app/views/layouts/europeana/feedback_button/application.html.erb +0 -14
- data/config/initializers/action_mailer.rb +0 -2
- data/lib/tasks/europeana_feedback_button_tasks.rake +0 -5
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/initializers/assets.rb +0 -12
- data/spec/dummy/config/initializers/session_store.rb +0 -4
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/helpers/feedback_helper_spec.rb +0 -0
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Europeana
|
3
4
|
module FeedbackButton
|
4
5
|
class Engine < ::Rails::Engine
|
@@ -11,8 +12,8 @@ module Europeana
|
|
11
12
|
end
|
12
13
|
|
13
14
|
config.autoload_paths += %W(
|
15
|
+
#{config.root}/app/validators
|
14
16
|
#{config.root}/app/views/concerns
|
15
|
-
#{config.root}/app/views/layouts
|
16
17
|
)
|
17
18
|
end
|
18
19
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Europeana
|
4
|
+
module FeedbackButton
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
desc 'Creates an initializer for Europeana::FeedbackButton.'
|
9
|
+
|
10
|
+
def copy_initializer_file
|
11
|
+
copy_file 'europeana_feedback_button.rb', 'config/initializers/europeana_feedback_button.rb'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Set the recipient of emails containing feedback submissions
|
4
|
+
# Europeana::FeedbackButton.mail_to = 'feedback@example.org'
|
5
|
+
# Europeana::FeedbackButton.mail_to = ENV['FEEDBACK_MAIL_TO']
|
6
|
+
|
7
|
+
# Set the URL to the privacy policy users must accept when submitting feedback.
|
8
|
+
# Europeana::FeedbackButton.privacy_policy_url = 'https://www.europeana.eu/portal/rights/privacy.html'
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
RSpec.describe Europeana::FeedbackButton::FeedbackController do
|
3
4
|
def main_app
|
4
5
|
Rails.application.class.routes.url_helpers
|
@@ -7,33 +8,95 @@ RSpec.describe Europeana::FeedbackButton::FeedbackController do
|
|
7
8
|
routes { Europeana::FeedbackButton::Engine.routes }
|
8
9
|
|
9
10
|
describe 'POST create' do
|
10
|
-
|
11
|
-
subject { post :create, params }
|
11
|
+
subject { -> { post :create, params: params } }
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
let(:valid_params) do
|
14
|
+
{ type: 'comment', text: 'This is good, five words!',
|
15
|
+
page: main_app.root_path, privacy_policy: '1', format: :json }
|
16
|
+
end
|
17
|
+
let(:json) { JSON.parse(response.body) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
Europeana::FeedbackButton.mail_to = mail_to
|
21
|
+
end
|
22
|
+
|
23
|
+
shared_examples 'feedback creation failure' do
|
24
|
+
it 'should not queue an email job' do
|
25
|
+
expect { subject.call }.to_not change(ActionMailer::Base.deliveries, :length)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return JSON' do
|
29
|
+
subject.call
|
30
|
+
expect(response.content_type).to eq('application/json')
|
16
31
|
end
|
17
32
|
|
33
|
+
it 'should include "success": "false"' do
|
34
|
+
subject.call
|
35
|
+
expect(json['success']).to be(false)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should include "message"' do
|
39
|
+
subject.call
|
40
|
+
expect(json['message']).to be_present
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
shared_examples 'feedback creation success' do
|
18
45
|
it 'should queue an email job' do
|
19
|
-
expect { subject }.to change(ActionMailer::Base.deliveries, :length)
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
46
|
+
expect { subject.call }.to change(ActionMailer::Base.deliveries, :length).by(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should have response status code 200' do
|
50
|
+
subject.call
|
51
|
+
expect(response.status).to eq(200)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return JSON' do
|
55
|
+
subject.call
|
56
|
+
expect(response.content_type).to eq('application/json')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should include "success": "true"' do
|
60
|
+
subject.call
|
61
|
+
expect(json['success']).to be(true)
|
62
|
+
end
|
28
63
|
end
|
29
64
|
|
30
|
-
context '
|
31
|
-
|
32
|
-
|
65
|
+
context 'with recipient configured' do
|
66
|
+
let(:mail_to) { 'feedback@example.com' }
|
67
|
+
|
68
|
+
context 'with valid params' do
|
69
|
+
let(:params) { valid_params }
|
70
|
+
|
71
|
+
it_behaves_like 'feedback creation success'
|
33
72
|
end
|
34
73
|
|
35
|
-
|
36
|
-
|
74
|
+
context 'with invalid params' do
|
75
|
+
let(:params) { valid_params.except(:text) }
|
76
|
+
|
77
|
+
it_behaves_like 'feedback creation failure'
|
78
|
+
|
79
|
+
it 'should have response status code 400' do
|
80
|
+
subject.call
|
81
|
+
expect(response.status).to eq(400)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'includes error messages' do
|
85
|
+
subject.call
|
86
|
+
expect(json['errors']['text']).to be_present
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'without recipient configured' do
|
92
|
+
let(:mail_to) { nil }
|
93
|
+
let(:params) { valid_params }
|
94
|
+
|
95
|
+
it_behaves_like 'feedback creation failure'
|
96
|
+
|
97
|
+
it 'should have response status code 500' do
|
98
|
+
subject.call
|
99
|
+
expect(response.status).to eq(500)
|
37
100
|
end
|
38
101
|
end
|
39
102
|
end
|
data/spec/dummy/Rakefile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
4
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
5
|
|
5
|
-
|
6
|
+
require_relative 'config/application'
|
6
7
|
|
7
8
|
Rails.application.load_tasks
|
@@ -5,9 +5,10 @@
|
|
5
5
|
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
9
|
//
|
10
10
|
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
12
12
|
//
|
13
|
+
//= require rails-ujs
|
13
14
|
//= require_tree .
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any
|
10
|
-
*
|
11
|
-
* file per style scope.
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
12
|
*
|
13
13
|
*= require_tree .
|
14
14
|
*= require_self
|
@@ -1,14 +1,14 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
10
7
|
|
11
|
-
<%=
|
8
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
9
|
+
</head>
|
12
10
|
|
13
|
-
|
11
|
+
<body>
|
12
|
+
<%= yield %>
|
13
|
+
</body>
|
14
14
|
</html>
|
@@ -1,9 +1,13 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<style>
|
6
|
+
/* Email styles need to be inline */
|
7
|
+
</style>
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
<%= yield %>
|
12
|
+
</body>
|
9
13
|
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/spec/dummy/bin/bundle
CHANGED
data/spec/dummy/bin/rails
CHANGED
data/spec/dummy/bin/rake
CHANGED
data/spec/dummy/bin/setup
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
include FileUtils
|
4
6
|
|
5
7
|
# path to your application root.
|
6
|
-
APP_ROOT =
|
8
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
9
|
+
|
10
|
+
def system!(*args)
|
11
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
12
|
+
end
|
7
13
|
|
8
|
-
|
14
|
+
chdir APP_ROOT do
|
9
15
|
# This script is a starting point to setup your application.
|
10
|
-
# Add necessary setup steps to this file
|
16
|
+
# Add necessary setup steps to this file.
|
11
17
|
|
12
18
|
puts '== Installing dependencies =='
|
13
|
-
system 'gem install bundler --conservative'
|
14
|
-
system
|
15
|
-
|
16
|
-
# puts "\n== Copying sample files =="
|
17
|
-
# unless File.exist?("config/database.yml")
|
18
|
-
# system "cp config/database.yml.sample config/database.yml"
|
19
|
-
# end
|
19
|
+
system! 'gem install bundler --conservative'
|
20
|
+
system('bundle check') || system!('bundle install')
|
20
21
|
|
21
|
-
|
22
|
-
system
|
22
|
+
# Install JavaScript dependencies if using Yarn
|
23
|
+
# system('bin/yarn')
|
23
24
|
|
24
25
|
puts "\n== Removing old logs and tempfiles =="
|
25
|
-
system '
|
26
|
-
system 'rm -rf tmp/cache'
|
26
|
+
system! 'bin/rails log:clear tmp:clear'
|
27
27
|
|
28
28
|
puts "\n== Restarting application server =="
|
29
|
-
system '
|
29
|
+
system! 'bin/rails restart'
|
30
30
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
include FileUtils
|
6
|
+
|
7
|
+
# path to your application root.
|
8
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
9
|
+
|
10
|
+
def system!(*args)
|
11
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
12
|
+
end
|
13
|
+
|
14
|
+
chdir APP_ROOT do
|
15
|
+
# This script is a way to update your development environment automatically.
|
16
|
+
# Add necessary update steps to this file.
|
17
|
+
|
18
|
+
puts '== Installing dependencies =='
|
19
|
+
system! 'gem install bundler --conservative'
|
20
|
+
system('bundle check') || system!('bundle install')
|
21
|
+
|
22
|
+
# Install JavaScript dependencies if using Yarn
|
23
|
+
# system('bin/yarn')
|
24
|
+
|
25
|
+
puts "\n== Removing old logs and tempfiles =="
|
26
|
+
system! 'bin/rails log:clear tmp:clear'
|
27
|
+
|
28
|
+
puts "\n== Restarting application server =="
|
29
|
+
system! 'bin/rails restart'
|
30
|
+
end
|
data/spec/dummy/bin/yarn
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
5
|
+
Dir.chdir(APP_ROOT) do
|
6
|
+
exec 'yarnpkg', *ARGV
|
7
|
+
rescue Errno::ENOENT
|
8
|
+
warn 'Yarn executable was not detected in the system.'
|
9
|
+
warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
|
10
|
+
exit 1
|
11
|
+
end
|
data/spec/dummy/config.ru
CHANGED
@@ -1,32 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require File.expand_path('../boot', __FILE__)
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'boot'
|
4
|
+
|
5
|
+
require 'rails'
|
6
|
+
require 'active_model/railtie'
|
7
|
+
require 'active_job/railtie'
|
6
8
|
require 'action_controller/railtie'
|
7
9
|
require 'action_mailer/railtie'
|
8
10
|
require 'action_view/railtie'
|
9
|
-
require 'sprockets/railtie'
|
10
|
-
# require 'rails/test_unit/railtie'
|
11
11
|
|
12
12
|
Bundler.require(*Rails.groups)
|
13
|
+
|
13
14
|
require 'europeana/feedback_button'
|
14
15
|
|
15
16
|
module Dummy
|
16
17
|
class Application < Rails::Application
|
17
|
-
#
|
18
|
-
|
19
|
-
# -- all .rb files in that directory are automatically loaded.
|
18
|
+
# Initialize configuration defaults for originally generated Rails version.
|
19
|
+
config.load_defaults 5.2
|
20
20
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
26
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
27
|
-
# config.i18n.default_locale = :de
|
28
|
-
|
29
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
30
|
-
# config.active_record.raise_in_transactional_callbacks = true
|
21
|
+
# Settings in config/environments/* take precedence over those specified here.
|
22
|
+
# Application configuration can go into files in config/initializers
|
23
|
+
# -- all .rb files in that directory are automatically loaded after loading
|
24
|
+
# the framework and any gems in your application.
|
31
25
|
end
|
32
26
|
end
|