Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solidus_dev_support update #10

Merged
merged 4 commits into from
Nov 6, 2020
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
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ jobs:
executor: solidusio_extensions/mysql
steps:
- solidusio_extensions/run-tests
lint-code:
executor: solidusio_extensions/sqlite-memory
steps:
- solidusio_extensions/lint-code

workflows:
"Run specs on supported Solidus versions":
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
- lint-code

"Weekly run specs against master":
triggers:
- schedule:
Expand Down
8 changes: 4 additions & 4 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,17 +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
daysUntilClose: false
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
staleLabel: stale
# 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
recent activity. It might 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
closeComment: false
2 changes: 2 additions & 0 deletions .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
issues=false
exclude-labels=infrastructure
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
require:
- solidus_dev_support/rubocop

AllCops:
NewCops: disable


RSpec/MultipleExpectations:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# SolidusFeeds
# Solidus Feeds

[![CircleCI](https://circleci.com/gh/nebulab/solidus_feeds.svg?style=shield)](https://circleci.com/gh/nebulab/solidus_feeds)
[![codecov](https://codecov.io/gh/nebulab/solidus_feeds/branch/master/graph/badge.svg)](https://codecov.io/gh/nebulab/solidus_feeds)

<!-- Explain what your extension does. -->
igorbp marked this conversation as resolved.
Show resolved Hide resolved
A framework for producing and publishing feeds on Solidus.

## Installation
Expand All @@ -13,20 +17,21 @@ gem 'solidus_feeds'
Bundle your dependencies and run the installation generator:

```shell
bundle
bundle exec rails g solidus_feeds:install
bin/rails generate solidus_feeds:install
```

## Usage

<!-- Explain how to use your extension once it's been installed. -->
igorbp marked this conversation as resolved.
Show resolved Hide resolved

⚠️ *This is work in progress, once done the following is expected to be the final interface* ⚠️

Define and publish your own feeds

```ruby
# initializer/spree.rb

SolidusFeeds.register :google_merchant_shoes do |feed|
SolidusFeeds.config.register :google_merchant_shoes do |feed|
taxon = Spree::Taxon.find_by(name: "Shoes")
products = Spree::Product.available.in_taxon(taxon)

Expand All @@ -41,7 +46,7 @@ The publisher's `#call` method is expected to yield an IO-like object that respo
At this point the feed can be generated and published using:

```ruby
SolidusFeeds.find(:google_merchant_shoes).publish
SolidusFeeds.config.find(:google_merchant_shoes).publish
```

### Serving the feed from the products controller (legacy)
Expand Down Expand Up @@ -96,7 +101,6 @@ app if it does not exist, then it will run specs. The dummy app can be regenerat
`bin/rake extension:test_app`.

```shell
bundle
bin/rake
```

Expand All @@ -121,22 +125,29 @@ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands t

Here's an example:

```shell
```
$ bin/rails server
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop
```

### Releasing new versions
### Updating the changelog

Your new extension version can be released using `gem-release` like this:
Before and after releases the changelog should be updated to reflect the up-to-date status of
the project:

```shell
bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
bin/rake changelog
git add CHANGELOG.md
git commit -m "Update the changelog"
```

### Releasing new versions

Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.

## License

Copyright (c) 2020 [name of extension author], released under the New BSD License.
2 changes: 1 addition & 1 deletion bin/rails-sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ app_root = 'sandbox'
unless File.exist? "#{app_root}/bin/rails"
warn 'Creating the sandbox app...'
Dir.chdir "#{__dir__}/.." do
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
system "#{__dir__}/sandbox" or begin
warn 'Automatic creation of the sandbox app failed'
exit 1
end
Expand Down
2 changes: 2 additions & 0 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ unbundled bundle exec rails generate spree:install \
--user_class=Spree::User \
--enforce_available_locales=true \
--with-authentication=false \
--payment-method=none \
$@

unbundled bundle exec rails generate solidus:auth:install
unbundled bundle exec rails generate ${extension_name}:install

echo
echo "🚀 Sandbox app successfully created for $extension_name!"
Expand Down
15 changes: 10 additions & 5 deletions lib/generators/solidus_feeds/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ module SolidusFeeds
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, type: :boolean, default: false
source_root File.expand_path('templates', __dir__)

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

def add_javascripts
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_feeds\n" # rubocop:disable Metrics/LineLength
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_feeds\n" # rubocop:disable Metrics/LineLength
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_feeds\n"
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_feeds\n"
end

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

def add_migrations
run 'bin/rails railties:install:migrations FROM=solidus_feeds'
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 Metrics/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'
else
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/solidus_feeds/install/templates/initializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

SolidusFeeds.configure do |config|
# TODO: Remember to change this with the actual preferences you have implemented!
# config.sample_preference = 'sample_value'
end
3 changes: 1 addition & 2 deletions lib/solidus_feeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'solidus_core'
require 'solidus_support'

require 'solidus_feeds/configuration'
require 'solidus_feeds/version'
require 'solidus_feeds/feed'
require 'solidus_feeds/feeds'
require 'solidus_feeds/engine'
41 changes: 41 additions & 0 deletions lib/solidus_feeds/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'solidus_feeds/feed'

module SolidusFeeds
class Configuration
# Define here the settings for this extensions, e.g.:
#
# attr_accessor :my_setting

def register(name, &builder)
feeds[name.to_sym] = Feed.new(&builder)
end

def find(name)
feeds.fetch(name)
end

private

def feeds
@feeds ||= {}
end
end

class << self
def configuration
@configuration ||= Configuration.new
end

alias config configuration

def reset_config!
@configuration
end

def configure
yield configuration
end
end
end
6 changes: 6 additions & 0 deletions lib/solidus_feeds/feed.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

class SolidusFeeds::Feed
attr_accessor :generator, :publisher

def initialize
yield(self) if block_given?
end

def generate(output)
generator.call(output)
end
Expand Down
15 changes: 0 additions & 15 deletions lib/solidus_feeds/feeds.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/solidus_feeds/testing_support/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

FactoryBot.define do
end
2 changes: 1 addition & 1 deletion solidus_feeds.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
spec.add_dependency 'solidus_support', '~> 0.5'

spec.add_development_dependency 'solidus_dev_support'
spec.add_development_dependency 'solidus_dev_support', '~> 2.1'
end
31 changes: 0 additions & 31 deletions spec/solidus_feeds/feeds_spec.rb

This file was deleted.

29 changes: 29 additions & 0 deletions spec/solidus_feeds_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'
require 'stringio'
require 'csv'

RSpec.describe SolidusFeeds do
before { described_class.reset_config! }

let(:io) { StringIO.new }
let(:string_io_publisher) { ->(&block) { block.call(io) } }
let(:csv_generator) {
->(io) {
csv = CSV.new(io)
csv << ["some", "data"]
csv << ["another", "line"]
}
}

it 'allows to register, generate, and publish feeds' do
described_class.configure do |config|
config.register :foo do |feed|
feed.publisher = string_io_publisher
feed.generator = csv_generator
end
end

described_class.config.find(:foo).publish
expect(io.string).to eq("some,data\nanother,line\n")
end
end
18 changes: 11 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
# Run Coverage report
require 'solidus_dev_support/rspec/coverage'

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
}
# Create the dummy app if it's still missing.
dummy_env = "#{__dir__}/dummy/config/environment.rb"
system 'bin/rake extension:test_app' unless File.exist? dummy_env
require dummy_env

# 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 }
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }

# Requires factories defined in lib/solidus_feeds/factories.rb
require 'solidus_feeds/factories'
# Requires factories defined in lib/solidus_feeds/testing_support/factories.rb
require 'solidus_feeds/testing_support/factories'

RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = false

if Spree.solidus_gem_version < Gem::Version.new('2.11')
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
end
end