Skip to content

Commit

Permalink
Merge pull request #25 from nebulab/elia/dev-support-updates
Browse files Browse the repository at this point in the history
Update to the latest solidus-dev-support templates + UI improvements
  • Loading branch information
Flavio Auciello authored Jun 26, 2020
2 parents ff78003 + b734edf commit 24a6ed0
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ pkg
spec/dummy
spec/examples.txt
/sandbox
.rvmrc
.ruby-version
.ruby-gemset
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--color
--format documentation
--require spec_helper
24 changes: 0 additions & 24 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
require:
- solidus_dev_support/rubocop

Metrics/LineLength:
Enabled: true
Max: 120

Rails/ApplicationJob:
Enabled: false

Rails/SkipsModelValidations:
Exclude:
- db/migrate/**/*
- spec/**/*
- sandbox/**/*

RSpec/LetSetup:
Enabled: false

RSpec/MultipleExpectations:
# Default is 1
Max: 5

RSpec/NestedGroups:
# Default is 3
Max: 6
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020 Nebulab SRL and other contributors
Copyright (c) 2020 Nebulab SRLs and other contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end

Each list of processors can be configured to add, remove, or replace any of the default processors.

## Configuration
### Advanced Configuration

To define your own processors (in this example for products), add to the spree
initializer:
Expand All @@ -114,15 +114,23 @@ source file. The `processors` classes are responsible of the import of a single
row of the source file; every processor has a `call` method (with an input
`context`) which makes a specific action and updates the context if needed.

## Testing
## Development

First bundle your dependencies, then run `rake`. `rake` will default to building
the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using
`rake test_app`.
### Testing the extension

First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
`bin/rake extension:test_app`.

```shell
bundle
bundle exec rake
bin/setup
bin/rake
```

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

```shell
bundle exec rubocop
```

When testing your application's integration with this extension you may use its factories.
Expand All @@ -132,14 +140,14 @@ Simply add this require statement to your spec_helper:
require 'solidus_importer/factories'

```
Sandbox app
-----------

To run this extension in a sandboxed Solidus application you can run `bin/sandbox`
The path for the sandbox app is `./sandbox` and `bin/rails` will forward any Rails command
to `sandbox/bin/rails`.
### Running the sandbox

Example:
To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
`sandbox/bin/rails`.

Here's an example:

```shell
$ bin/rails server
Expand All @@ -149,15 +157,14 @@ $ bin/rails server
Use Ctrl-C to stop
```

Releasing
---------
### Releasing new versions

Your new extension version can be released using `gem-release` like this:

```shell
bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
```

## About
## License

Copyright (c) 2020 Nebulab SRL, released under the New BSD License
Copyright (c) 2020 Nebulab SRLs, released under the New BSD License

This file was deleted.

14 changes: 14 additions & 0 deletions app/views/spree/admin/solidus_importer/imports/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="col-4">
<div class="field">
<%= f.label :import_type %><br>
<%= f.select :import_type, [nil] + @import_types %>
</div>
</div>
<div class="col-3">
<div class="field">
<%= f.label :file %><br>
<%= f.file_field :file %>
</div>
</div>
</div>
13 changes: 5 additions & 8 deletions app/views/spree/admin/solidus_importer/imports/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<%
admin_layout('full-width')
admin_breadcrumb(
t('spree.solidus_importer.title'),
t('spree.solidus_importer.imports')
)
%>
<% admin_layout('full-width') %>
<% admin_breadcrumb(t('spree.solidus_importer.title'), t('spree.solidus_importer.imports')) %>
<% content_for :page_actions do %>
<li>
Expand Down Expand Up @@ -75,7 +70,9 @@ admin_breadcrumb(
</table>
<% else %>
<div class="no-objects-found">
<%= render 'spree/admin/shared/no_objects_found', resource: SolidusImporter::Import %>
<%= render 'spree/admin/shared/no_objects_found',
resource: SolidusImporter::Import,
new_resource_url: new_object_url %>
</div>
<% end %>
Expand Down
31 changes: 8 additions & 23 deletions app/views/spree/admin/solidus_importer/imports/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
<%
admin_layout('full-width')
admin_breadcrumb(
t('spree.solidus_importer.title'),
link_to(t('spree.solidus_importer.imports'), admin_solidus_importer_imports_path)
)
%>
<% admin_breadcrumb t('spree.solidus_importer.title'), link_to(t('spree.solidus_importer.imports'), admin_solidus_importer_imports_path) %>
<%= form_for [:admin, @import], method: :post, html: { multipart: true } do |f| %>
<div data-hook="admin_solidus_importer_import_form_fields">
<div class="row">
<div class="col-6">
<%= f.label :file %><br>
<%= f.file_field :file %>
<fieldset>
<% @import_types.each do |type| %>
<label>
<%= f.radio_button :import_type, type %>
<%= t(type, scope: 'spree.solidus_importer.import_types') %>
</label>
<% end %>
<%= f.button t('spree.admin.solidus_importer.create'), class: 'btn btn-primary' %>
</fieldset>
</div>
<fieldset class="no-border-top">
<%= render partial: 'spree/shared/error_messages', locals: { target: @import } %>
<%= render partial: 'form', locals: { f: f } %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= f.submit t('spree.actions.create'), class: 'btn btn-primary' %>
</div>
</div>
</fieldset>
<% end %>

16 changes: 4 additions & 12 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

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
if %w[g generate].include? ARGV.first
exec "#{__dir__}/rails-engine", *ARGV
else
exec "#{__dir__}/rails-sandbox", *ARGV
end

Dir.chdir app_root
exec 'bin/rails', *ARGV
File renamed without changes.
2 changes: 0 additions & 2 deletions bin/sandbox_rails → bin/rails-sandbox
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

app_root = 'sandbox'

unless File.exist? "#{app_root}/bin/rails"
Expand Down
1 change: 1 addition & 0 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ unbundled bundle exec rails generate spree:install \
--auto-accept \
--user_class=Spree::User \
--enforce_available_locales=true \
--with-authentication=false \
$@

unbundled bundle exec rails generate solidus:auth:install
Expand Down
11 changes: 11 additions & 0 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

Spree::Backend::Config.configure do |config|
config.menu_items << config.class::MenuItem.new(
:imports,
'download',
condition: -> { can?(:admin, Spree::Product) },
label: :importer,
url: :admin_solidus_importer_imports_path
)
end
5 changes: 3 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ en:
messages: Messages
target_entity: Target entity
title: &solidus_importer_title
Solidus Importer
Importer
updated_at: Updated at
updated_at_from: 'Updated at: start date'
updated_at_to: 'Updated at: end date'
import_type: Import Type
import_types:
customers: Customers
orders: Orders
products: Products

admin:
tab:
solidus_importer: *solidus_importer_title
importer: *solidus_importer_title
solidus_importer:
create: Import!
new: New import
3 changes: 2 additions & 1 deletion lib/solidus_importer/engine.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

require 'spree/core'
require 'solidus_importer'

module SolidusImporter
class Engine < Rails::Engine
include SolidusSupport::EngineExtensions::Decorators
include SolidusSupport::EngineExtensions

isolate_namespace ::Spree

Expand Down
6 changes: 3 additions & 3 deletions solidus_importer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Gem::Specification.new do |spec|
spec.license = 'BSD-3-Clause'

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/nebulab/solidus_importer'
spec.metadata['source_code_uri'] = 'https://github.com/nebulab/solidus_importer#readme'
spec.metadata['changelog_uri'] = 'https://github.com/nebulab/solidus_importer/releases'

spec.required_ruby_version = Gem::Requirement.new('~> 2.4')
spec.required_ruby_version = Gem::Requirement.new('~> 2.5')

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
spec.add_dependency 'solidus_support', '~> 0.4.0'
spec.add_dependency 'solidus_support', '~> 0.5'

spec.add_development_dependency 'solidus_dev_support'
end
29 changes: 8 additions & 21 deletions spec/features/admin/solidus_importer/imports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
describe 'New import form' do
subject(:described_path) { spree.new_admin_solidus_importer_import_path }

before do
visit described_path
end
before { visit described_path }

let(:import_file) { page.find 'input[name="solidus_importer_import[file]"]' }
let(:import_button) do
page.find 'button[type="submit"]'
end
let(:import_button) { page.find '[type="submit"]' }

it 'display import form with available types and "import!" button' do
expect(import_file).to be_visible
expect(page).to have_css('input[name="solidus_importer_import[import_type]"]', count: 3)
expect(page).to have_css('select[name="solidus_importer_import[import_type]"] > option', count: 4)
expect(import_button).to be_visible
end
end
Expand All @@ -30,25 +26,16 @@
let!(:shipping_method) { create :shipping_method }

let(:import_file) { page.find 'input[name="solidus_importer_import[file]"]' }
let(:product_import_type) do
page.find 'input[name="solidus_importer_import[import_type]"][value="products"]'
end
let(:orders_import_type) do
page.find 'input[name="solidus_importer_import[import_type]"][value="orders"]'
end
let(:import_button) do
page.find 'button[type="submit"]'
end
let(:import_button) { page.find '[type="submit"]' }
let(:products_csv_file) { solidus_importer_fixture_path('products.csv') }
let(:import_type) { product_import_type }
let(:no_import_type) { false }
let(:import_type) { "products" }

before do
allow(::SolidusImporter::ImportJob).to receive(:perform_later)

visit described_path
import_file.set products_csv_file
import_type.click unless no_import_type
select import_type, from: :solidus_importer_import_import_type if import_type
import_button.click
end

Expand All @@ -58,15 +45,15 @@
end

context 'when no import type is selected' do
let(:no_import_type) { true }
let(:import_type) { nil }

it 'fails creating a new import' do
expect(page).to have_content("Import type can't be blank")
end
end

context 'when the wrong import type is selected', skip: 'Not implemented yet' do
let(:import_type) { orders_import_type }
let(:import_type) { "orders" }

it 'fails creating a new import' do
expect(page).to have_content('Import failed!')
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
# Run Coverage report
require 'solidus_dev_support/rspec/coverage'

require File.expand_path('dummy/config/environment.rb', __dir__)
require File.expand_path('dummy/config/environment.rb', __dir__).tap { |file|
# Create the dummy app if it's still missing.
system 'bin/rake extension:test_app' unless File.exist? file
}

# Requires factories and other useful helpers defined in spree_core.
require 'solidus_dev_support/rspec/feature_helper'
Expand Down

0 comments on commit 24a6ed0

Please sign in to comment.