solidus_newsletter 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +35 -0
  3. data/.gitignore +2 -2
  4. data/.rubocop.yml +23 -0
  5. data/.ruby-version +1 -1
  6. data/Gemfile +41 -14
  7. data/README.md +4 -3
  8. data/Rakefile +4 -19
  9. data/app/controllers/spree/admin/newsletters_controller.rb +5 -3
  10. data/app/controllers/spree/newsletters_controller.rb +12 -6
  11. data/app/models/spree/newsletter.rb +3 -1
  12. data/app/overrides/spree/admin/configurations/index/add_newsletter_to_admin_configurations_menu.html.erb.deface +3 -3
  13. data/app/overrides/spree/admin/shared/_configuration_menu/add_newsletter_to_admin_configurations_sidebar_menu.html.erb.deface +1 -1
  14. data/app/views/spree/admin/newsletters/_form.html.erb +4 -4
  15. data/app/views/spree/admin/newsletters/edit.html.erb +8 -2
  16. data/app/views/spree/shared/_newsletter.html.erb +14 -7
  17. data/config/locales/en.yml +2 -1
  18. data/config/locales/es-MX.yml +8 -6
  19. data/config/routes.rb +2 -0
  20. data/db/migrate/20180209175720_add_spree_newsletters_table.rb +1 -1
  21. data/lib/solidus_newsletter/configuration.rb +2 -0
  22. data/lib/solidus_newsletter/engine.rb +12 -10
  23. data/lib/solidus_newsletter/testing_support/factories.rb +8 -0
  24. data/lib/solidus_newsletter/version.rb +3 -1
  25. data/lib/solidus_newsletter.rb +8 -0
  26. data/solidus_newsletter.gemspec +22 -20
  27. data/spec/controllers/spree/admin/newsletters_controller_spec.rb +4 -2
  28. data/spec/controllers/spree/newsletters_controller_spec.rb +38 -7
  29. data/spec/models/spree/newsletter_spec.rb +3 -1
  30. data/spec/spec_helper.rb +21 -35
  31. metadata +44 -136
  32. data/.travis.yml +0 -29
  33. data/Gemfile.lock +0 -410
  34. data/lib/solidus_newsletter/factories.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b7181ee38f3d6ae3e37561089ad3d4a6f3d9c0f4f2da4a7a2eeb0b2f0eeaf6e
4
- data.tar.gz: 82677d2a3786f839cb907d9aed94f837c940fa1ae733c69b98224e559d4348d0
3
+ metadata.gz: 41468f6f1439adf05a6b7dae4b31fe167caab4dc5514d8d47c601a405df8be21
4
+ data.tar.gz: 53101a190127763f6c958aa3dda6d0d5019186740a9d0340ac7ca600a71788e3
5
5
  SHA512:
6
- metadata.gz: 785f34dfa1c29564b687afa7d9a14d38eed374b64ae95382d2d58130360125ecc89e7f3dee1fa8e4bea125f0722c1cd7000cc66dd115c10b9d0c0cb804eb6ba1
7
- data.tar.gz: 27700c0900df2675e1fb28783ca5fa68132f6bb815e2939bedc110969e115658fb87c0d9d84520ac3a62faba6445a2bea01047733b05759ba64d6bfe4b1d443d
6
+ metadata.gz: 6084ba67e4124a99a74478519f47715aa25e93bd87e5af7dd65af73efd87eef880c2e03e9152e2fe53e44ed44af6d249fb7bba9a18a18b6caed1f46a7bb40031
7
+ data.tar.gz: 1b3c91d263292366da9112d0546a6d66c70fc2ad3cc21c7d9ac57a9799704fa736e4c39522945abdc6f02849b3fe939aef8998ab2a7d3b4d8c4be2b8f039d6cd
@@ -0,0 +1,35 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ # Always take the latest version of the orb, this allows us to
5
+ # run specs against Solidus supported versions only without the need
6
+ # to change this configuration every time a Solidus version is released
7
+ # or goes EOL.
8
+ solidusio_extensions: solidusio/extensions@volatile
9
+
10
+ jobs:
11
+ run-specs-with-postgres:
12
+ executor: solidusio_extensions/postgres
13
+ steps:
14
+ - solidusio_extensions/run-tests
15
+ run-specs-with-mysql:
16
+ executor: solidusio_extensions/mysql
17
+ steps:
18
+ - solidusio_extensions/run-tests
19
+
20
+ workflows:
21
+ "Run specs on supported Solidus versions":
22
+ jobs:
23
+ - run-specs-with-postgres
24
+ - run-specs-with-mysql
25
+ "Weekly run specs against master":
26
+ triggers:
27
+ - schedule:
28
+ cron: "0 0 * * 4" # every Thursday
29
+ filters:
30
+ branches:
31
+ only:
32
+ - master
33
+ jobs:
34
+ - run-specs-with-postgres
35
+ - run-specs-with-mysql
data/.gitignore CHANGED
@@ -7,9 +7,9 @@
7
7
  .project
8
8
  .sass-cache
9
9
  coverage
10
- Gemfile.lock
11
10
  tmp
12
11
  nbproject
13
12
  pkg
14
13
  *.swp
15
- spec/dummy
14
+ spec/dummy
15
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require:
2
+ - solidus_dev_support/rubocop
3
+
4
+ inherit_gem:
5
+ solidus_dev_support: .rubocop.yml
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - spec/dummy/**/*
10
+ - vendor/**/*
11
+
12
+ Rails/SkipsModelValidations:
13
+ Exclude:
14
+ - db/migrate/**/*
15
+
16
+ Gemspec/OrderedDependencies:
17
+ Enabled: false
18
+
19
+ Style/RegexpLiteral:
20
+ Enabled: false
21
+
22
+ Style/MissingRespondToMissing:
23
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 3.0.0
data/Gemfile CHANGED
@@ -1,25 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
2
5
 
3
6
  branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
- gem 'solidus', github: 'solidusio/solidus', branch: branch
5
- gem 'solidus_i18n', github: 'solidusio-contrib/solidus_i18n', branch: 'master'
6
-
7
- if branch == 'master' || branch >= 'v2.3'
8
- gem 'rails', '~> 5.1.0'
9
- elsif branch >= 'v2.0'
10
- gem 'rails', '~> 5.0.0'
11
- gem 'rails-controller-testing', group: :test
7
+
8
+ solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2')
9
+ %w[solidusio/solidus solidusio/solidus_frontend]
10
+ else
11
+ %w[solidusio/solidus] * 2
12
+ end
13
+
14
+ gem 'solidus', github: solidus_git, branch: branch
15
+ gem 'solidus_api', github: solidus_git, branch: branch
16
+ gem 'solidus_backend', github: solidus_git, branch: branch
17
+ gem 'solidus_core', github: solidus_git, branch: branch
18
+ gem 'solidus_frontend', github: solidus_frontend_git, branch: branch
19
+ gem 'solidus_sample', github: solidus_git, branch: branch
20
+
21
+ # Needed to help Bundler figure out how to resolve dependencies,
22
+ # otherwise it takes forever to resolve them.
23
+ # See https://github.com/bundler/bundler/issues/6677
24
+ gem 'rails', ENV.fetch('RAILS_VERSION', nil)
25
+
26
+ # Provides basic authentication functionality for testing parts of your engine
27
+ gem 'solidus_auth_devise'
28
+
29
+ case ENV.fetch('DB', nil)
30
+ when 'mysql'
31
+ gem 'mysql2'
32
+ when 'postgresql'
33
+ gem 'pg'
12
34
  else
13
- gem 'rails', '~> 4.2.0'
14
- gem 'rails_test_params_backport', group: :test
35
+ gem 'sqlite3'
15
36
  end
16
37
 
17
- gem 'pg', '~> 0.21'
18
- gem 'sqlite3'
19
- gem 'mysql2'
38
+ group :test do
39
+ gem 'rails-controller-testing'
40
+ gem 'rspec-activemodel-mocks'
41
+ end
20
42
 
21
43
  group :development, :test do
22
- gem 'i18n-tasks', '~> 0.9' if branch == 'master'
44
+ gem 'factory_bot', '> 4.10.0'
45
+ gem 'pry-rails'
23
46
  end
24
47
 
25
48
  gemspec
49
+
50
+ # Use a local Gemfile to include development dependencies that might not be
51
+ # relevant for the project or for other contributors, e.g.: `gem 'pry-debug'`.
52
+ eval_gemfile 'Gemfile-local' if File.exist? 'Gemfile-local'
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- # Solidus Newsletter
2
- [![Build Status](https://travis-ci.org/jtapia/solidus_newsletter.svg?branch=master)](https://travis-ci.org/jtapia/solidus_newsletter)<br />
1
+ SolidusNewsletter
2
+ =================
3
+ [![CircleCI](https://circleci.com/gh/jtapia/solidus_newsletter.svg?style=shield)](https://circleci.com/gh/jtapia/solidus_newsletter)
3
4
 
4
5
  Basic Overview
5
6
  -----
@@ -26,4 +27,4 @@ Using the newsletter form
26
27
 
27
28
  ```ruby
28
29
  <%= render partial: 'spree/shared/newsletter' %>
29
- ```
30
+ ```
data/Rakefile CHANGED
@@ -1,21 +1,6 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ # frozen_string_literal: true
3
2
 
4
- require 'rspec/core/rake_task'
5
- require 'spree/testing_support/extension_rake'
3
+ require 'solidus_dev_support/rake_tasks'
4
+ SolidusDevSupport::RakeTasks.install
6
5
 
7
- RSpec::Core::RakeTask.new
8
-
9
- task :default do
10
- if Dir["spec/dummy"].empty?
11
- Rake::Task[:test_app].invoke
12
- Dir.chdir("../../")
13
- end
14
- Rake::Task[:spec].invoke
15
- end
16
-
17
- desc 'Generates a dummy app for testing'
18
- task :test_app do
19
- ENV['LIB_NAME'] = 'solidus_newsletter'
20
- Rake::Task['extension:test_app'].invoke
21
- end
6
+ task default: 'extension:specs'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  module Admin
3
5
  class NewslettersController < Spree::Admin::BaseController
@@ -7,9 +9,9 @@ module Spree
7
9
 
8
10
  if (title == newsletter_params[:title] && text == newsletter_params[:text]) &&
9
11
  (newsletter_params[:title].present? && newsletter_params[:text])
10
- flash[:success] = Spree.t(:'newsletter.admin.success')
12
+ flash[:success] = I18n.t('spree.newsletter.admin.success')
11
13
  else
12
- flash[:error] = Spree.t(:'newsletter.admin.error')
14
+ flash[:error] = I18n.t('spree.newsletter.admin.error')
13
15
  end
14
16
 
15
17
  redirect_to admin_newsletters_edit_path
@@ -30,4 +32,4 @@ module Spree
30
32
  end
31
33
  end
32
34
  end
33
- end
35
+ end
@@ -1,15 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class NewslettersController < StoreController
3
5
  def create
4
- @newsletter = Spree::Newsletter.new(newsletter_params)
6
+ @newsletter = Spree::Newsletter.find_or_initialize_by(newsletter_params)
5
7
 
6
- if @newsletter.save
7
- flash[:success] = Spree.t(:'newsletter.controller.success')
8
+ if @newsletter.persisted?
9
+ flash[:notice] = I18n.t('spree.newsletter.controller.already_subscribed')
8
10
  else
9
- flash[:error] = Spree.t(:'newsletter.controller.error')
11
+ if @newsletter.save
12
+ flash[:success] = I18n.t('spree.newsletter.controller.success')
13
+ else
14
+ flash[:error] = I18n.t('spree.newsletter.controller.error')
15
+ end
10
16
  end
11
17
 
12
- redirect_to admin_newsletters_edit_path
18
+ redirect_to root_path
13
19
  end
14
20
 
15
21
  private
@@ -18,4 +24,4 @@ module Spree
18
24
  params.require(:newsletters).permit(:name, :email)
19
25
  end
20
26
  end
21
- end
27
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class Newsletter < Spree::Base
3
5
  validates :name, presence: true
4
6
  validates :email, presence: true, uniqueness: true
5
7
  end
6
- end
8
+ end
@@ -1,6 +1,6 @@
1
1
  <!-- insert_bottom "[data-hook='admin_configurations_menu']" -->
2
2
 
3
3
  <tr>
4
- <td><%= link_to Spree.t('newsletter.config_name'), admin_newsletters_edit_path %></td>
5
- <td><%= Spree.t('newsletter.config_description') %></td>
6
- </tr>
4
+ <td><%= link_to I18n.t('spree.newsletter.config_name'), admin_newsletters_edit_path %></td>
5
+ <td><%= I18n.t('spree.newsletter.config_description') %></td>
6
+ </tr>
@@ -1,3 +1,3 @@
1
1
  <!-- insert_bottom "[data-hook='admin_configurations_sidebar_menu']" -->
2
2
 
3
- <%= settings_tab_item Spree.t('newsletter.config_name'), admin_newsletters_edit_path %>
3
+ <%= settings_tab_item I18n.t('spree.newsletter.config_name'), admin_newsletters_edit_path %>
@@ -3,7 +3,7 @@
3
3
  <fieldset class='no-border-bottom'>
4
4
  <div class='field'>
5
5
  <%= f.field_container :title do %>
6
- <%= f.label Spree.t(:'newsletter.title') %>
6
+ <%= f.label I18n.t('spree.newsletter.title') %>
7
7
  <%= f.text_field :title, class: 'fullwidth', value: SolidusNewsletter::Config[:title] %>
8
8
  <%= f.error_message_on :title %>
9
9
  <% end %>
@@ -11,7 +11,7 @@
11
11
 
12
12
  <div class='field'>
13
13
  <%= f.field_container :text do %>
14
- <%= f.label Spree.t(:'newsletter.form.text') %>
14
+ <%= f.label I18n.t('spree.newsletter.form.text') %>
15
15
  <%= f.text_field :text, class: 'fullwidth', value: SolidusNewsletter::Config[:text] %>
16
16
  <%= f.error_message_on :text %>
17
17
  <% end %>
@@ -24,7 +24,7 @@
24
24
  <fieldset class='currency no-border-bottom'>
25
25
  <div class='field'>
26
26
  <%= f.field_container :title do %>
27
- <%= f.label Spree.t(:'newsletter.form.title') %>
27
+ <%= f.label I18n.t('spree.newsletter.form.title') %>
28
28
  <%= f.text_field :title, class: 'fullwidth', value: SolidusNewsletter::Config[:title] %>
29
29
  <%= f.error_message_on :title %>
30
30
  <% end %>
@@ -36,7 +36,7 @@
36
36
  <fieldset class='currency no-border-bottom'>
37
37
  <div class='field'>
38
38
  <%= f.field_container :text do %>
39
- <%= f.label Spree.t(:'newsletter.form.text') %>
39
+ <%= f.label I18n.t('spree.newsletter.form.text') %>
40
40
  <%= f.text_field :text, class: 'fullwidth', value: SolidusNewsletter::Config[:text] %>
41
41
  <%= f.error_message_on :text %>
42
42
  <% end %>
@@ -1,11 +1,17 @@
1
1
  <%= render 'spree/admin/shared/general_tabs' %>
2
2
 
3
- <% admin_breadcrumb(link_to(Spree.t(:'newsletter.admin_breadcrumb'), edit_admin_general_settings_path)) %>
3
+ <% admin_breadcrumb(
4
+ link_to(
5
+ I18n.t('spree.newsletter.admin_breadcrumb'),
6
+ edit_admin_general_settings_path
7
+ )
8
+ ) %>
4
9
 
5
10
  <%= form_for :newsletters, url: admin_newsletters_update_path, method: :put do |f| %>
6
11
  <fieldset class='no-border-top'>
7
12
  <%= render 'form', f: f %>
8
- <%= render 'spree/admin/shared/edit_resource_links', collection_url: edit_admin_general_settings_url %>
13
+ <%= render 'spree/admin/shared/edit_resource_links',
14
+ collection_url: edit_admin_general_settings_url %>
9
15
  </fieldset>
10
16
  <% end %>
11
17
 
@@ -1,23 +1,30 @@
1
1
  <section class='newsletter-section'>
2
- <h2 class='newsletter-section__title'><%= SolidusNewsletter::Config[:title] %></h2>
2
+ <h2 class='newsletter-section__title'>
3
+ <%= SolidusNewsletter::Config[:title].html_safe %>
4
+ </h2>
3
5
 
4
6
  <div class='newsletter-section__content row'>
5
- <%= form_for :newsletter, url: newsletters_update_path, method: :post do |f| %>
7
+ <%= form_for :newsletters, url: newsletters_path, method: :post do |f| %>
6
8
  <div class='field text col-md-3 col-sm-12 text-center'>
7
- <p><%= SolidusNewsletter::Config[:text] %></p>
9
+ <p><%= SolidusNewsletter::Config[:text].html_safe %></p>
8
10
  </div>
9
11
 
10
12
  <div class='field col-md-3 col-sm-6' id=<%= 'name' %>>
11
- <%= f.text_field :name, class: 'required fullwidth', autofocus: true, placeholder: Spree.t(:'newsletter.form.name') %>
13
+ <%= f.text_field :name,
14
+ class: 'required fullwidth',
15
+ placeholder: I18n.t('spree.newsletter.form.name') %>
12
16
  </div>
13
17
 
14
18
  <div class='field col-md-3 col-sm-6' id=<%= 'email' %>>
15
- <%= f.email_field :email, class: 'required fullwidth', placeholder: Spree.t(:'newsletter.form.email') %>
19
+ <%= f.email_field :email,
20
+ class: 'required fullwidth',
21
+ placeholder: I18n.t('spree.newsletter.form.email') %>
16
22
  </div>
17
23
 
18
24
  <div class='col-md-3 col-sm-6 form-buttons'>
19
- <%= f.submit Spree.t(:'newsletter.form.button'), class: 'newsletter-btn border-rounded small-text' %>
25
+ <%= f.submit I18n.t('spree.newsletter.form.button'),
26
+ class: 'newsletter-btn border-rounded small-text' %>
20
27
  </div>
21
28
  <% end %>
22
29
  </div>
23
- </section>
30
+ </section>
@@ -13,8 +13,9 @@ en:
13
13
  spree:
14
14
  newsletter:
15
15
  controller:
16
- sucess: Thank you to subscribe to our newsletter
16
+ success: Thank you to subscribe to our newsletter
17
17
  error: Something went wrong, please try again
18
+ already_subscribed: You're already registered
18
19
  admin:
19
20
  success: The newsletter was updated successfuly!
20
21
  error: Something went wrong, please try again
@@ -1,9 +1,10 @@
1
1
  es-MX:
2
2
  activerecord:
3
3
  attributes:
4
- name: Nombre
5
- email: Email
6
- text: Texto
4
+ spree/newsletter:
5
+ name: Nombre
6
+ email: Email
7
+ text: Texto
7
8
  models:
8
9
  spree/newsletter:
9
10
  one: Newsletter
@@ -12,8 +13,9 @@ es-MX:
12
13
  spree:
13
14
  newsletter:
14
15
  controller:
15
- sucess: Gracias por suscribirte a nuestro newsletter
16
- error: Hubo un problem, por favor intenta otra vez
16
+ success: Gracias por suscribirte a nuestro newsletter
17
+ error: Hubo un problema, por favor intenta otra vez
18
+ already_subscribed: Ya estas actualmente registrado
17
19
  admin:
18
20
  success: El texto del newsletter a sido actualizado correctamente
19
21
  error: El texto del newsletter no se a podido actualizar, intente más tarde
@@ -21,7 +23,7 @@ es-MX:
21
23
  title: Titulo
22
24
  text: Texto
23
25
  name: Nombre
24
- email: Correo Electronico
26
+ email: Correo Electrónico
25
27
  button: Enviar
26
28
  admin_breadcrumb: Newsletter
27
29
  config_name: Newsletter
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Spree::Core::Engine.routes.draw do
2
4
  namespace :admin do
3
5
  get '/newsletters/edit' => 'newsletters#edit'
@@ -4,7 +4,7 @@ class AddSpreeNewslettersTable < SolidusSupport::Migration[4.2]
4
4
  t.string :name
5
5
  t.string :email
6
6
 
7
- t.timestamps
7
+ t.timestamps null: false
8
8
  end
9
9
  end
10
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusNewsletter
2
4
  class Configuration < Spree::Preferences::Configuration
3
5
  preference :title, :string, default: ''
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusNewsletter
2
4
  class Engine < Rails::Engine
3
- require 'spree/core'
4
- isolate_namespace Spree
5
- engine_name 'solidus_newsletter'
5
+ include SolidusSupport::EngineExtensions
6
6
 
7
- config.autoload_paths += %W(#{config.root}/lib)
7
+ isolate_namespace ::Spree
8
+
9
+ engine_name 'solidus_newsletter'
8
10
 
9
11
  # use rspec for tests
10
12
  config.generators do |g|
@@ -15,12 +17,12 @@ module SolidusNewsletter
15
17
  SolidusNewsletter::Config = SolidusNewsletter::Configuration.new
16
18
  end
17
19
 
18
- def self.activate
19
- Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
20
- Rails.configuration.cache_classes ? require(c) : load(c)
21
- end
22
- end
20
+ # def self.activate
21
+ # Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
22
+ # Rails.configuration.cache_classes ? require(c) : load(c)
23
+ # end
24
+ # end
23
25
 
24
- config.to_prepare &method(:activate).to_proc
26
+ # config.to_prepare &method(:activate).to_proc
25
27
  end
26
28
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :newsletter, class: Spree::Newsletter do
5
+ name { 'User Test' }
6
+ email { 'user@test.com' }
7
+ end
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusNewsletter
2
- VERSION = '1.0'
4
+ VERSION = '1.1'
3
5
  end
@@ -1,2 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'solidus_core'
4
+ require 'solidus_backend'
5
+ require 'solidus_support'
6
+ require 'deface'
7
+
8
+ require 'solidus_newsletter/version'
9
+ require 'solidus_newsletter/configuration'
2
10
  require 'solidus_newsletter/engine'
@@ -1,10 +1,7 @@
1
- # encoding: UTF-8
2
- $:.push File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
3
2
 
4
- # Maintain your gem's version:
5
- require 'solidus_newsletter/version'
3
+ require_relative 'lib/solidus_newsletter/version'
6
4
 
7
- # Describe your gem and declare its dependencies:
8
5
  Gem::Specification.new do |s|
9
6
  s.name = 'solidus_newsletter'
10
7
  s.version = SolidusNewsletter::VERSION
@@ -14,24 +11,29 @@ Gem::Specification.new do |s|
14
11
  s.summary = 'Solidus Newsletter extension'
15
12
  s.description = 'Adds a newsletter form to the homepage'
16
13
 
17
- # s.files = Dir['{app,config,models,db,lib}/**/*'] + %w(MIT-LICENSE Rakefile README.md)
18
14
  s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
16
  s.require_path = 'lib'
20
17
  s.requirements << 'none'
21
18
 
22
- solidus_version = ['>= 1.2', '< 3']
19
+ if s.respond_to?(:metadata)
20
+ s.metadata['homepage_uri'] = s.homepage
21
+ s.metadata['source_code_uri'] = 'https://github.com/jtapia/solidus_newsletter'
22
+ s.metadata['rubygems_mfa_required'] = 'true'
23
+ end
24
+
25
+ s.required_ruby_version = Gem::Requirement.new('>= 2.5')
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
30
+
31
+ solidus_version = ['>= 2.5', '< 4']
32
+
23
33
  s.add_dependency 'solidus_core', solidus_version
24
- s.add_dependency 'solidus_backend', solidus_version
25
- s.add_dependency 'solidus_api', solidus_version
26
- s.add_dependency 'solidus_support'
27
-
28
- s.add_development_dependency 'database_cleaner', '~> 1.6'
29
- s.add_development_dependency 'factory_bot', '~> 4.4'
30
- s.add_development_dependency 'ffaker'
31
- s.add_development_dependency 'rspec-rails', '~> 3.3'
32
- s.add_development_dependency 'simplecov', '~> 0.14'
33
- s.add_development_dependency 'rspec-activemodel-mocks'
34
- s.add_development_dependency 'webmock'
35
- s.add_development_dependency 'byebug'
36
- end
34
+ s.add_dependency 'solidus_support', '~> 0.5'
37
35
 
36
+ s.add_development_dependency 'solidus_backend', solidus_version
37
+ s.add_development_dependency 'solidus_dev_support', '~> 2.5'
38
+ s.add_development_dependency 'solidus_frontend', solidus_version
39
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe Spree::Admin::NewslettersController, type: :controller do
5
+ RSpec.describe Spree::Admin::NewslettersController, type: :controller do
4
6
  stub_authorization!
5
7
 
6
8
  before do
@@ -24,4 +26,4 @@ describe Spree::Admin::NewslettersController, type: :controller do
24
26
  expect(flash[:error]).to include('Something went wrong, please try again')
25
27
  end
26
28
  end
27
- end
29
+ end
@@ -1,19 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe Spree::NewslettersController, type: :controller do
5
+ RSpec.describe Spree::NewslettersController, type: :controller do
6
+ let(:newsletter) { create(:newsletter) }
7
+
4
8
  context '#create' do
5
- it 'returns true' do
6
- post :create, params: { newsletters: { name: 'User Test', email: 'user@test.com' } }
9
+ it 'returns true new object' do
10
+ post :create,
11
+ params: {
12
+ newsletters: {
13
+ name: 'User Test',
14
+ email: 'user@test.com'
15
+ }
16
+ }
7
17
 
8
18
  expect(response.status).to eq(302)
9
- expect(flash[:success]).to include(Spree.t('newsletter.controller.success'))
19
+ expect(flash[:success])
20
+ .to include(I18n.t('spree.newsletter.controller.success'))
10
21
  end
11
22
 
12
23
  it 'returns false' do
13
- post :create, params: { newsletters: { name: '', email: '' } }
24
+ post :create,
25
+ params: {
26
+ newsletters: {
27
+ name: '',
28
+ email: ''
29
+ }
30
+ }
31
+
32
+ expect(response.status).to eq(302)
33
+ expect(flash[:error]).to include(I18n.t('spree.newsletter.controller.error'))
34
+ end
35
+
36
+ it 'returns already added' do
37
+ post :create,
38
+ params: {
39
+ newsletters: {
40
+ name: newsletter.name,
41
+ email: newsletter.email
42
+ }
43
+ }
14
44
 
15
45
  expect(response.status).to eq(302)
16
- expect(flash[:error]).to include(Spree.t('newsletter.controller.error'))
46
+ expect(flash[:notice])
47
+ .to include(I18n.t('spree.newsletter.controller.already_subscribed'))
17
48
  end
18
49
  end
19
- end
50
+ end