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.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +5 -0
  3. data/.rubocop.yml +2 -8
  4. data/.travis.yml +1 -2
  5. data/Gemfile +11 -6
  6. data/README.md +17 -7
  7. data/Rakefile +1 -0
  8. data/app/controllers/europeana/feedback_button/application_controller.rb +28 -0
  9. data/app/controllers/europeana/feedback_button/feedback_controller.rb +20 -12
  10. data/app/mailers/europeana/feedback_button/feedback_mailer.rb +9 -6
  11. data/app/models/europeana/feedback_button/feedback.rb +21 -0
  12. data/app/validators/europeana/feedback_button/word_count_validator.rb +26 -0
  13. data/app/views/concerns/europeana/feedback_button/feedbackable_view.rb +5 -5
  14. data/app/views/europeana/feedback_button/feedback_mailer/post.text.erb +2 -0
  15. data/bin/rails +19 -5
  16. data/config/routes.rb +1 -0
  17. data/europeana-feedback-button.gemspec +7 -10
  18. data/lib/europeana/feedback_button.rb +32 -1
  19. data/lib/europeana/feedback_button/engine.rb +2 -1
  20. data/lib/europeana/feedback_button/version.rb +2 -1
  21. data/lib/generators/europeana/feedback_button/install_generator.rb +15 -0
  22. data/lib/generators/europeana/feedback_button/templates/europeana_feedback_button.rb +8 -0
  23. data/spec/controllers/feedback_controller_spec.rb +82 -19
  24. data/spec/dummy/Rakefile +2 -1
  25. data/spec/dummy/app/assets/config/manifest.js +3 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +2 -1
  27. data/spec/dummy/app/assets/stylesheets/application.css +3 -3
  28. data/spec/dummy/app/controllers/application_controller.rb +1 -3
  29. data/spec/dummy/app/controllers/welcome_controller.rb +3 -5
  30. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  31. data/spec/dummy/app/jobs/application_job.rb +4 -0
  32. data/spec/dummy/app/mailers/application_mailer.rb +2 -1
  33. data/spec/dummy/app/views/layouts/application.html.erb +9 -9
  34. data/spec/dummy/app/views/layouts/mailer.html.erb +10 -6
  35. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  36. data/spec/dummy/bin/bundle +2 -1
  37. data/spec/dummy/bin/rails +2 -1
  38. data/spec/dummy/bin/rake +1 -0
  39. data/spec/dummy/bin/setup +16 -16
  40. data/spec/dummy/bin/update +30 -0
  41. data/spec/dummy/bin/yarn +11 -0
  42. data/spec/dummy/config.ru +3 -1
  43. data/spec/dummy/config/application.rb +12 -18
  44. data/spec/dummy/config/boot.rb +3 -2
  45. data/spec/dummy/config/environment.rb +2 -1
  46. data/spec/dummy/config/environments/development.rb +24 -20
  47. data/spec/dummy/config/environments/production.rb +22 -26
  48. data/spec/dummy/config/environments/test.rb +10 -6
  49. data/spec/dummy/config/initializers/application_controller_renderer.rb +9 -0
  50. data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
  51. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  52. data/spec/dummy/config/initializers/europeana_feedback_button.rb +5 -0
  53. data/spec/dummy/config/initializers/filter_parameter_logging.rb +1 -0
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -6
  55. data/spec/dummy/config/locales/en.yml +10 -0
  56. data/spec/dummy/config/puma.rb +36 -0
  57. data/spec/dummy/config/routes.rb +2 -57
  58. data/spec/dummy/config/spring.rb +8 -0
  59. data/spec/dummy/package.json +5 -0
  60. data/spec/dummy/public/404.html +6 -6
  61. data/spec/dummy/public/422.html +6 -6
  62. data/spec/dummy/public/500.html +6 -6
  63. data/{app/assets/images/europeana_feedback_button/.keep → spec/dummy/public/apple-touch-icon-precomposed.png} +0 -0
  64. data/{app/models/.keep → spec/dummy/public/apple-touch-icon.png} +0 -0
  65. data/spec/lib/europeana/feedback_button_spec.rb +21 -0
  66. data/spec/mailers/feedback_mailer_spec.rb +54 -0
  67. data/spec/models/feedback_spec.rb +25 -0
  68. data/spec/spec_helper.rb +11 -1
  69. metadata +52 -53
  70. data/QUICKSTART.md +0 -30
  71. data/app/assets/javascripts/europeana_feedback_button/application.js +0 -13
  72. data/app/assets/stylesheets/europeana_feedback_button/application.css +0 -15
  73. data/app/helpers/europeana/feedback_button/application_helper.rb +0 -7
  74. data/app/helpers/europeana/feedback_button/feedback_helper.rb +0 -12
  75. data/app/views/layouts/europeana/feedback_button/application.html.erb +0 -14
  76. data/config/initializers/action_mailer.rb +0 -2
  77. data/lib/tasks/europeana_feedback_button_tasks.rake +0 -5
  78. data/spec/dummy/README.rdoc +0 -28
  79. data/spec/dummy/app/mailers/.keep +0 -0
  80. data/spec/dummy/app/models/.keep +0 -0
  81. data/spec/dummy/config/database.yml +0 -25
  82. data/spec/dummy/config/initializers/assets.rb +0 -12
  83. data/spec/dummy/config/initializers/session_store.rb +0 -4
  84. data/spec/dummy/config/secrets.yml +0 -22
  85. 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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Europeana
3
4
  module FeedbackButton
4
- VERSION = '0.0.5'
5
+ VERSION = '0.0.6'
5
6
  end
6
7
  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
- let(:params) { { locale: 'en', type: 'comment', text: 'This is good, five words!', url: main_app.root_path(locale: 'en'), format: :json } }
11
- subject { post :create, params }
11
+ subject { -> { post :create, params: params } }
12
12
 
13
- context 'with recipient configured' do
14
- before do
15
- Rails.application.config.x.feedback_mail_to = 'feedback@example.com'
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
- # it '' do
22
- # message_delivery = instance_double(ActionMailer::MessageDelivery)
23
- # expect(ServiceMailer).to receive(:new_user).with(@user).and_return(message_delivery)
24
- # expect(message_delivery).to receive(:deliver_later)
25
- # subject
26
- # expect { subject }.to change { Delayed::Job.where("handler LIKE '%FeedbackMailer%'").count }.by(1)
27
- # end
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 'without recipient configured' do
31
- before do
32
- Rails.application.config.x.feedback_mail_to = nil
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
- it 'should not queue an email job' do
36
- expect { subject }.to_not change(ActionMailer::Base.deliveries, :length)
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
@@ -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
- require File.expand_path('../config/application', __FILE__)
6
+ require_relative 'config/application'
6
7
 
7
8
  Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
3
+ //= link europeana/feedback_button_manifest.js
@@ -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 styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
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,6 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class ApplicationController < ActionController::Base
3
- # Prevent CSRF attacks by raising an exception.
4
- # For APIs, you may want to use :null_session instead.
5
- protect_from_forgery with: :exception
6
4
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Static pages controller
4
- class WellcomeController < ApplicationController
5
- def index
6
- end
2
+
3
+ class WelcomeController < ApplicationController
4
+ def index; end
7
5
  end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ApplicationHelper
3
4
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@exmaple.com'
4
+ default from: 'from@example.com'
4
5
  layout 'mailer'
5
6
  end
@@ -1,14 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
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
- <%= yield %>
8
+ <%= stylesheet_link_tag 'application', media: 'all' %>
9
+ </head>
12
10
 
13
- </body>
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
14
  </html>
@@ -1,9 +1,13 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
- </head>
6
- <body>
7
- <%= yield %>
8
- </body>
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 %>
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4
5
  load Gem.bin_path('bundler', 'bundle')
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
4
5
  require_relative '../config/boot'
5
6
  require 'rails/commands'
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require_relative '../config/boot'
4
5
  require 'rake'
5
6
  Rake.application.run
@@ -1,30 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
- require 'pathname'
3
+
4
+ require 'fileutils'
5
+ include FileUtils
4
6
 
5
7
  # path to your application root.
6
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
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
- Dir.chdir APP_ROOT do
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 'bundle check || bundle install'
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
- puts "\n== Preparing database =="
22
- system 'bin/rake db:setup'
22
+ # Install JavaScript dependencies if using Yarn
23
+ # system('bin/yarn')
23
24
 
24
25
  puts "\n== Removing old logs and tempfiles =="
25
- system 'rm -f log/*'
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 'touch tmp/restart.txt'
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
@@ -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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # This file is used by Rack-based servers to start the application.
3
4
 
4
- require ::File.expand_path('../config/environment', __FILE__)
5
+ require_relative 'config/environment'
6
+
5
7
  run Rails.application
@@ -1,32 +1,26 @@
1
1
  # frozen_string_literal: true
2
- require File.expand_path('../boot', __FILE__)
3
2
 
4
- # Pick the frameworks you want:
5
- require 'active_record/railtie'
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
- # Settings in config/environments/* take precedence over those specified here.
18
- # Application configuration should go into files in config/initializers
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
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
22
- # Run 'rake -D time' for a list of tasks for finding time zone names. Default is UTC.
23
- # config.time_zone = 'Central Time (US & Canada)'
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