Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .git-blame-ignore-revs
# Convert to standardrb
18cd5bfae471a37917a8e4cb8cad341067716648
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
ruby-version: "3.4"
bundler-cache: true
- name: Lint Ruby files
run: bundle exec rubocop -ESP
run: bundle exec standardrb
23 changes: 5 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,20 @@ jobs:
- "7.2"
- "8.0"
ruby-version:
- "3.2"
- "3.3"
- "3.4"
solidus-branch:
- "v4.1"
- "v4.2"
- "v4.3"
- "v4.4"
- "v4.5"
- "v4.6"
- "main"
database:
- "postgresql"
- "mysql"
- "sqlite"
exclude:
- rails-version: "7.2"
solidus-branch: "v4.3"
- rails-version: "7.2"
solidus-branch: "v4.2"
- rails-version: "7.2"
solidus-branch: "v4.1"
- ruby-version: "3.4"
rails-version: "7.0"
- ruby-version: "3.2"
rails-version: "8.0"
- solidus-branch: "v4.3"
rails-version: "8.0"
- solidus-branch: "v4.4"
rails-version: "8.0"
- rails-version: "8.0"
solidus-branch: "v4.4"
steps:
- uses: actions/checkout@v4
- name: Run extension tests
Expand Down
18 changes: 3 additions & 15 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
require:
- solidus_dev_support/rubocop
- standard

AllCops:
NewCops: disable

Rails/SkipsModelValidations:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NestedGroups:
Max: 4
inherit_gem:
standard: config/base.yml
50 changes: 29 additions & 21 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
solidus_git, solidus_frontend_git = if (branch == 'main') || (branch >= 'v3.2')
%w[solidusio/solidus solidusio/solidus_frontend]
else
%w[solidusio/solidus] * 2
end
gem 'solidus', github: solidus_git, branch: branch
gem 'solidus_frontend', github: solidus_frontend_git, branch: branch
branch = ENV.fetch("SOLIDUS_BRANCH", "main")

# 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'
gem "solidus", github: "solidusio/solidus", branch: branch

# The `solidus_frontend` gem is deprecated and isn't expected to have major
# version updates after v3.2.
if branch >= "v3.2"
gem "solidus_frontend"
elsif branch == "main"
gem "solidus_frontend", github: "solidusio/solidus_frontend", branch: branch
else
gem "solidus_frontend", github: "solidusio/solidus", branch: branch
end

rails_requirement_string = ENV.fetch("RAILS_VERSION", "~> 8.0")
gem "rails", rails_requirement_string

gem "state_machines", "0.6.0"

# Provides basic authentication functionality for testing parts of your engine
gem 'solidus_auth_devise'
gem "solidus_auth_devise"

case ENV['DB']
when 'mysql'
gem 'mysql2'
when 'postgresql'
gem 'pg'
case ENV["DB"]
when "mysql"
gem "mysql2"
when "postgresql"
gem "pg"
else
gem 'sqlite3'
rails_version = Gem::Requirement.new(rails_requirement_string).requirements[0][1]
sqlite_version = (rails_version < Gem::Version.new(7.2)) ? "~> 1.4" : "~> 2.0"

gem "sqlite3", sqlite_version
end

gemspec
Expand All @@ -36,4 +44,4 @@ gemspec
#
# We use `send` instead of calling `eval_gemfile` to work around an issue with
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ bin/setup
bin/rake
```

To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
To run [Standard](https://github.com/standardrb/standard)

```shell
bundle exec rubocop
bundle exec standardrb --fix
```

When testing your application's integration with this extension you may use its factories.
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'solidus_dev_support/rake_tasks'
require "solidus_dev_support/rake_tasks"
SolidusDevSupport::RakeTasks.install

task default: 'extension:specs'
task default: "extension:specs"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module SolidusImporter
class ImportRowsController < BaseController
before_action :load_data, only: %i[show]

def show; end
def show
end

private

Expand All @@ -15,8 +16,8 @@ def load_data
return unless (@log_entry = ::Spree::LogEntry.find_by(source: @import_row))

@log_details = JSON.parse(@log_entry.details)
target_class = @log_details['class_name']&.constantize
@target_entity = target_class.find_by(id: @log_details['id']) if target_class
target_class = @log_details["class_name"]&.constantize
@target_entity = target_class.find_by(id: @log_details["id"]) if target_class
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ImportsController < ResourceController
def index
@search = ::SolidusImporter::Import.ransack(params[:q])
@imports = @search.result(distinct: true)
.page(params[:page])
.per(params[:per_page] || Spree::Config[:orders_per_page])
.order(id: :desc)
.page(params[:page])
.per(params[:per_page] || Spree::Config[:orders_per_page])
.order(id: :desc)
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/solidus_importer/import_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ImportJob < ApplicationJob
retry_on ActiveRecord::Deadlocked

def perform(source, import_type = nil)
raise ArgumentError, 'Missing import source' unless source
raise ArgumentError, "Missing import source" unless source

if source.is_a?(Integer)
perform_import_from_model(source)
Expand Down
26 changes: 13 additions & 13 deletions app/models/solidus_importer/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

module SolidusImporter
class Import < ApplicationRecord
self.table_name = 'solidus_importer_imports'
self.table_name = "solidus_importer_imports"

attr_accessor :importer

has_many :rows,
class_name: 'SolidusImporter::Row',
class_name: "SolidusImporter::Row",
inverse_of: :import,
dependent: :destroy
if Rails.gem_version >= Gem::Version.new('7.1')
if Rails.gem_version >= Gem::Version.new("7.1")
enum :state, {
created: 'created',
processing: 'processing',
failed: 'failed',
completed: 'completed'
created: "created",
processing: "processing",
failed: "failed",
completed: "completed"
}
else
enum state: {
created: 'created',
processing: 'processing',
failed: 'failed',
completed: 'completed'
created: "created",
processing: "processing",
failed: "failed",
completed: "completed"
}
end

Expand All @@ -42,9 +42,9 @@ def finished?
end

def import_file=(path)
raise SolidusImporter::Exception, 'Existing file required' if !path || !File.exist?(path)
raise SolidusImporter::Exception, "Existing file required" if !path || !File.exist?(path)

self.file = File.open(path, 'r')
self.file = File.open(path, "r")
end

def self.ransackable_attributes(_auth_object = nil)
Expand Down
22 changes: 11 additions & 11 deletions app/models/solidus_importer/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

module SolidusImporter
class Row < ApplicationRecord
self.table_name = 'solidus_importer_rows'
self.table_name = "solidus_importer_rows"

belongs_to :import,
class_name: 'SolidusImporter::Import',
class_name: "SolidusImporter::Import",
inverse_of: :rows

if Rails.gem_version >= Gem::Version.new('7.1')
if Rails.gem_version >= Gem::Version.new("7.1")
serialize :data, coder: JSON
enum :state, {
created: 'created',
processing: 'processing',
failed: 'failed',
completed: 'completed'
created: "created",
processing: "processing",
failed: "failed",
completed: "completed"
}
else
serialize :data, JSON
enum state: {
created: 'created',
processing: 'processing',
failed: 'failed',
completed: 'completed'
created: "created",
processing: "processing",
failed: "failed",
completed: "completed"
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/solidus_importer/spree_core_importer_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.import(user, params)

if completed_at
order.completed_at = completed_at
order.state = 'complete'
order.state = "complete"
order.save!
end

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/spree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Spree::Backend::Config.configure do |config|
config.menu_items << config.class::MenuItem.new(
:imports,
'download',
"download",
condition: -> { can?(:admin, Spree::Product) },
label: :importer,
url: :admin_solidus_importer_imports_path
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20191216101011_create_solidus_importer_imports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class CreateSolidusImporterImports < ActiveRecord::Migration[5.2]
def change
create_table :solidus_importer_imports do |t|
t.string :import_type
t.string :state, null: false, default: 'created', limit: 32
t.string :file, null: false, default: '', limit: 1024
t.string :state, null: false, default: "created", limit: 32
t.string :file, null: false, default: "", limit: 1024
t.text :messages

t.timestamps null: false
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20191216101012_create_solidus_importer_rows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CreateSolidusImporterRows < ActiveRecord::Migration[5.2]
def change
create_table :solidus_importer_rows do |t|
t.belongs_to :import
t.string :state, null: false, default: 'created', limit: 32
t.string :state, null: false, default: "created", limit: 32
t.text :data
t.text :messages

Expand Down
6 changes: 3 additions & 3 deletions examples/importers/custom_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module Importers
class CustomImporter < ::SolidusImporter::BaseImporter
def after_import(context)
ActionMailer::Base.mail(
from: 'some_email',
to: 'some_email_2',
subject: 'Import finished',
from: "some_email",
to: "some_email_2",
subject: "Import finished",
body: "Ending context:\n#{context.to_json}"
).deliver_now
end
Expand Down
6 changes: 3 additions & 3 deletions examples/processors/notify_on_failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def call(context)
return if context[:success]

ActionMailer::Base.mail(
from: 'some_email',
to: 'some_email_2',
subject: 'Row process error',
from: "some_email",
to: "some_email_2",
subject: "Row process error",
body: "Row context:\n#{context.to_json}"
).deliver_now
end
Expand Down
16 changes: 8 additions & 8 deletions lib/generators/solidus_importer/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ module SolidusImporter
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, type: :boolean, default: false
source_root File.expand_path('templates', __dir__)
source_root File.expand_path("templates", __dir__)

def copy_initializer
template 'initializer.rb', 'config/initializers/solidus_importer.rb'
template "initializer.rb", "config/initializers/solidus_importer.rb"
end

def add_javascripts
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_importer\n"
append_file "vendor/assets/javascripts/spree/backend/all.js", "//= require spree/backend/solidus_importer\n"
end

def add_stylesheets
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_importer\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
inject_into_file "vendor/assets/stylesheets/spree/backend/all.css", " *= require spree/backend/solidus_importer\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
end

def add_migrations
run 'bin/rails railties:install:migrations FROM=solidus_importer'
run "bin/rails railties:install:migrations FROM=solidus_importer"
end

def run_migrations
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
run_migrations = options[:auto_run_migrations] || ["", "y", "Y"].include?(ask("Would you like to run the migrations now? [Y/n]")) # rubocop:disable Layout/LineLength
if run_migrations
run 'bin/rails db:migrate'
run "bin/rails db:migrate"
else
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
puts "Skipping bin/rails db:migrate, don't forget to run it!" # rubocop:disable Rails/Output
end
end
end
Expand Down
Loading