diff --git a/.gem_release.yml b/.gem_release.yml new file mode 100644 index 00000000..10950b32 --- /dev/null +++ b/.gem_release.yml @@ -0,0 +1,5 @@ +bump: + recurse: false + file: 'lib/solidus_i18n/version.rb' + message: Bump SolidusI18n to %{version} + tag: true diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 00000000..d9f65632 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 200bf862..bcd4aea4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,16 @@ +*.gem \#* *~ .#* .DS_Store .idea -.localeapp/locales .project +.sass-cache coverage -config/locales/en.yml Gemfile.lock tmp nbproject pkg -*.sw? +*.swp spec/dummy -.rvmrc -.sass-cache -public/spree -.ruby-gemset +spec/examples.txt diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..83e16f80 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index b14089d6..544964ec 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,13 +1,4 @@ ---- -inherit_from: .hound.yml +require: + - solidus_dev_support/rubocop -Metrics/BlockLength: - Exclude: - - spec/**/* - - lib/tasks/**/* - -AllCops: - Exclude: - - 'spec/dummy/**/*' - - 'bin/**/*' - - 'vendor/**/*' +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..4be0610e --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,18 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-01-24 11:23:54 +0100 using RuboCop version 0.76.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +RSpec/DescribeClass: + Exclude: + - 'spec/solidus_i18n_spec.rb' + +# Offense count: 2 +# Configuration parameters: IgnoreSharedExamples. +RSpec/NamedSubject: + Exclude: + - 'spec/solidus_i18n_spec.rb' diff --git a/Gemfile b/Gemfile index c1a1d0c1..42c0d41c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,31 @@ # frozen_string_literal: true source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } branch = ENV.fetch('SOLIDUS_BRANCH', 'master') gem 'solidus', github: 'solidusio/solidus', branch: branch -if ENV['DB'] == 'mysql' - gem 'mysql2', '~> 0.4.10' +# Needed to help Bundler figure out how to resolve dependencies, +# otherwise it takes forever to resolve them. +# See https://github.com/bundler/bundler/issues/6677 +gem 'rails', '>0.a' + +case ENV['DB'] +when 'mysql' + gem 'mysql2' +when 'postgresql' + gem 'pg' else - gem 'pg', '~> 0.21' + gem 'sqlite3' end group :development, :test do gem 'i18n-tasks', '~> 0.9' if branch == 'master' - gem 'pry-rails' end gemspec + +# Use a local Gemfile to include development dependencies that might not be +# relevant for the project or for other contributors, e.g.: `gem 'pry-debug'`. +eval_gemfile 'Gemfile-local' if File.exist? 'Gemfile-local' diff --git a/LICENSE.md b/LICENSE similarity index 90% rename from LICENSE.md rename to LICENSE index d3fc7cb6..8600a3f0 100644 --- a/LICENSE.md +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011-2015 Spree Commerce Inc., and other contributors. +Copyright (c) 2011-2015 Spree Commerce Inc. and other contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -9,7 +9,7 @@ are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name Spree nor the names of its contributors may be used to + * Neither the name Solidus nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/Rakefile b/Rakefile index 2849dd10..dc8d888e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,30 +1,12 @@ # frozen_string_literal: true -require 'bundler' -Bundler::GemHelper.install_tasks - -require 'rspec/core/rake_task' -RSpec::Core::RakeTask.new - -task :default do - if Dir['spec/dummy'].empty? - Rake::Task[:test_app].invoke - Dir.chdir('../../') - end - Rake::Task[:spec].invoke -end - -require 'spree/testing_support/common_rake' -desc 'Generates a dummy app for testing' -task :test_app do - ENV['LIB_NAME'] = 'solidus_i18n' - Rake::Task['common:test_app'].invoke -end +require 'solidus_dev_support/rake_tasks' +SolidusDevSupport::RakeTasks.install require 'solidus_i18n' namespace :solidus_i18n do desc 'Update by retrieving the latest Solidus locale files' - task :update_default do + task update_default: :environment do require 'open-uri' puts 'Fetching latest Solidus locale file' location = 'https://raw.github.com/solidusio/solidus/master/core/config/locales/en.yml' @@ -36,3 +18,5 @@ namespace :solidus_i18n do File.join File.dirname(__FILE__), 'config/locales' end end + +task default: 'extension:specs' diff --git a/bin/console b/bin/console new file mode 100755 index 00000000..f09a905e --- /dev/null +++ b/bin/console @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# frozen_string_literal: true + +require "bundler/setup" +require "solidus_i18n" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. +$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"]) + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/rails b/bin/rails index 80c3b2d6..c535fd20 100755 --- a/bin/rails +++ b/bin/rails @@ -1,7 +1,15 @@ #!/usr/bin/env ruby -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/solidus_i18n/engine', __FILE__) +# frozen_string_literal: true -require 'rails/all' -require 'rails/engine/commands' +app_root = 'spec/dummy' + +unless File.exist? "#{app_root}/bin/rails" + system "bin/rake", app_root or begin # rubocop:disable Style/AndOr + warn "Automatic creation of the dummy app failed" + exit 1 + end +end + +Dir.chdir app_root +exec 'bin/rails', *ARGV diff --git a/bin/setup b/bin/setup new file mode 100755 index 00000000..40d7811d --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +gem install bundler --conservative +bundle update +bundle exec rake clobber diff --git a/lib/generators/solidus_i18n/install/install_generator.rb b/lib/generators/solidus_i18n/install/install_generator.rb new file mode 100644 index 00000000..ac73abde --- /dev/null +++ b/lib/generators/solidus_i18n/install/install_generator.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module SolidusI18n + module Generators + class InstallGenerator < Rails::Generators::Base + class_option :auto_run_migrations, type: :boolean, default: false + + def add_migrations + run 'bundle exec rake railties:install:migrations FROM=solidus_i18n' + end + + def run_migrations + run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?( + ask('Would you like to run the migrations now? [Y/n]') + ) + if run_migrations + run 'bundle exec rake db:migrate' + else + puts 'Skipping rake db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output + end + end + end + end +end diff --git a/lib/solidus_i18n.rb b/lib/solidus_i18n.rb index 7205e294..4f6b57ac 100644 --- a/lib/solidus_i18n.rb +++ b/lib/solidus_i18n.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true require 'solidus_core' -require 'solidus_i18n/engine' +require 'solidus_support' + require 'solidus_i18n/version' +require 'solidus_i18n/engine' diff --git a/lib/solidus_i18n/engine.rb b/lib/solidus_i18n/engine.rb index 9692595f..0baf5024 100644 --- a/lib/solidus_i18n/engine.rb +++ b/lib/solidus_i18n/engine.rb @@ -1,7 +1,18 @@ # frozen_string_literal: true +require 'spree/core' + module SolidusI18n class Engine < Rails::Engine + include SolidusSupport::EngineExtensions::Decorators + + isolate_namespace ::Spree + engine_name 'solidus_i18n' + + # use rspec for tests + config.generators do |g| + g.test_framework :rspec + end end end diff --git a/lib/solidus_i18n/factories.rb b/lib/solidus_i18n/factories.rb new file mode 100644 index 00000000..745a01e4 --- /dev/null +++ b/lib/solidus_i18n/factories.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +FactoryBot.define do +end diff --git a/solidus_i18n.gemspec b/solidus_i18n.gemspec index 1199c587..c34408ba 100644 --- a/solidus_i18n.gemspec +++ b/solidus_i18n.gemspec @@ -1,31 +1,36 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +$:.push File.expand_path('lib', __dir__) require 'solidus_i18n/version' -Gem::Specification.new do |spec| - spec.name = 'solidus_i18n' - spec.version = SolidusI18n.version - spec.authors = ['Thomas von Deyen'] - spec.email = ['tvd@magiclabs.de'] +Gem::Specification.new do |s| + s.name = 'solidus_i18n' + s.version = SolidusI18n.version + s.summary = 'Provides locale information for use in Solidus.' + s.description = 'A collection of translations for Solidus.' - spec.summary = 'Provides locale information for use in Solidus.' - spec.description = 'A collection of translations for Solidus.' - spec.homepage = 'https://solidus.io' - spec.license = 'BSD-3-Clause' + s.required_ruby_version = '~> 2.4' - spec.files = Dir.chdir(File.expand_path(__dir__)) do + s.author = 'Thomas von Deyen' + s.email = 'tvd@magiclabs.de' + s.homepage = 'https://github.com/solidusio/solidus_i18n' + s.license = 'BSD-3-Clause' + + s.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end + s.test_files = Dir['spec/**/*'] + s.bindir = "exe" + s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } + s.require_paths = ["lib"] - spec.require_paths = ['lib'] + if s.respond_to?(:metadata) + s.metadata["homepage_uri"] = s.homepage if s.homepage + s.metadata["source_code_uri"] = s.homepage if s.homepage + end - spec.add_runtime_dependency 'solidus_core', ['>= 1.1', '< 3'] + s.add_runtime_dependency 'solidus_core', ['>= 1.1', '< 3'] + s.add_runtime_dependency 'solidus_support', '~> 0.4.0' - spec.add_development_dependency 'pry-rails', '~> 0.3.0' - spec.add_development_dependency 'rspec-rails', '~> 3.1' - spec.add_development_dependency 'rubocop', '~> 0.67.2' - spec.add_development_dependency 'simplecov', '~> 0.9' - spec.add_development_dependency 'sqlite3', '~> 1.3' + s.add_development_dependency 'solidus_dev_support' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 30530efa..7eb2c7a3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,19 +1,22 @@ # frozen_string_literal: true -require 'simplecov' -SimpleCov.start 'rails' - +# Configure Rails Environment ENV['RAILS_ENV'] ||= 'test' -begin - require File.expand_path('dummy/config/environment', __dir__) -rescue LoadError - puts 'Could not load dummy application. Please ensure you have run `bundle exec rake test_app`' - exit -end +# Run Coverage report +require 'solidus_dev_support/rspec/coverage' + +require File.expand_path('dummy/config/environment.rb', __dir__) -require 'pry' -require 'rspec/rails' +# Requires factories and other useful helpers defined in spree_core. +require 'solidus_dev_support/rspec/feature_helper' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } + +# Requires factories defined in lib/solidus_i18n/factories.rb +require 'solidus_i18n/factories' RSpec.configure do |config| config.fail_fast = false @@ -28,5 +31,3 @@ expectations.syntax = :expect end end - -Dir[File.join(File.dirname(__FILE__), '/support/**/*.rb')].each { |file| require file }