From 2ac97699c833d342659dc5503a164ced96d3ab7a Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 20 Nov 2017 17:47:35 -0800 Subject: [PATCH] Vaguely working gem (but totally not) --- Gemfile | 15 ++++++++++++ Rakefile | 21 +++++++++++++++++ lib/solidus_stock_transfers/factories.rb | 2 +- solidus_stock_transfers.gemspec | 18 ++++++++++----- .../admin/stock_transfers_controller_spec.rb | 2 ++ .../api/stock_transfers_controller_spec.rb | 4 ++++ .../api/transfer_items_controller_spec.rb | 4 ++++ spec/spec_helper.rb | 23 +++++++++++++++++++ spec/support/dummy_ability.rb | 5 ++++ spec/support/working_factories.rb | 13 +++++++++++ 10 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/dummy_ability.rb create mode 100644 spec/support/working_factories.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..77ec891 --- /dev/null +++ b/Gemfile @@ -0,0 +1,15 @@ +source "https://rubygems.org" + +branch = ENV.fetch('SOLIDUS_BRANCH', 'master') +gem "solidus", github: "solidusio/solidus", branch: branch + +gem 'pg' +gem 'mysql2' + +group :development, :test do + gem "pry-rails" +end + +gem 'deface', require: false + +gemspec diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7f2c0a9 --- /dev/null +++ b/Rakefile @@ -0,0 +1,21 @@ +require 'bundler' +Bundler::GemHelper.install_tasks + +require 'rspec/core/rake_task' +require 'spree/testing_support/common_rake' + +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 + +desc 'Generates a dummy app for testing' +task :test_app do + ENV['LIB_NAME'] = 'solidus_stock_transfers' + Rake::Task['common:test_app'].invoke +end diff --git a/lib/solidus_stock_transfers/factories.rb b/lib/solidus_stock_transfers/factories.rb index fe60bbe..6e7ead5 100644 --- a/lib/solidus_stock_transfers/factories.rb +++ b/lib/solidus_stock_transfers/factories.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them. # # Example adding this to your spec_helper will load these Factories for use: diff --git a/solidus_stock_transfers.gemspec b/solidus_stock_transfers.gemspec index 253c1f6..7b86021 100644 --- a/solidus_stock_transfers.gemspec +++ b/solidus_stock_transfers.gemspec @@ -5,28 +5,34 @@ require 'solidus_stock_transfers/version' Gem::Specification.new do |s| s.name = 'solidus_stock_transfers' s.version = SolidusStockTransfers::VERSION - s.summary = 'TODO' - s.description = 'TODO' + s.summary = 'Stock transfer interface for solidus' + s.description = 'An admin interface for transfering stock between StockLocations. Extracted from Solidus 2.5' s.license = 'BSD-3-Clause' - # s.author = 'You' - # s.email = 'you@example.com' + s.author = 'John Hawthorn' + s.email = 'john@stembolt.com' # s.homepage = 'http://www.example.com' s.files = Dir["{app,config,db,lib}/**/*", 'LICENSE', 'Rakefile', 'README.md'] s.test_files = Dir['test/**/*'] - s.add_dependency 'solidus_core', '~> 1.0' + s.add_dependency 'solidus_core', ['>= 2.5.x', '< 3'] + s.add_dependency 'solidus_support' + s.add_dependency 'deface' s.add_development_dependency 'capybara' + s.add_development_dependency 'ffaker' s.add_development_dependency 'poltergeist' s.add_development_dependency 'coffee-rails' s.add_development_dependency 'sass-rails' s.add_development_dependency 'database_cleaner' - s.add_development_dependency 'factory_girl' + s.add_development_dependency 'factory_bot' s.add_development_dependency 'rspec-rails' s.add_development_dependency 'rubocop', '0.37.2' s.add_development_dependency 'rubocop-rspec', '1.4.0' s.add_development_dependency 'simplecov' s.add_development_dependency 'sqlite3' + s.add_development_dependency 'capybara-screenshot' + s.add_development_dependency 'rspec-activemodel-mocks' + s.add_development_dependency 'rails-controller-testing' end diff --git a/spec/controllers/spree/admin/stock_transfers_controller_spec.rb b/spec/controllers/spree/admin/stock_transfers_controller_spec.rb index 5856430..20ae557 100644 --- a/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +++ b/spec/controllers/spree/admin/stock_transfers_controller_spec.rb @@ -4,6 +4,8 @@ module Spree describe Admin::StockTransfersController, type: :controller do stub_authorization! + routes { Spree::Core::Engine.routes } + let(:warehouse) { StockLocation.create(name: "Warehouse") } let(:ny_store) { StockLocation.create(name: "NY Store") } let(:la_store) { StockLocation.create(name: "LA Store") } diff --git a/spec/requests/spree/api/stock_transfers_controller_spec.rb b/spec/requests/spree/api/stock_transfers_controller_spec.rb index bd8a55f..4fe95be 100644 --- a/spec/requests/spree/api/stock_transfers_controller_spec.rb +++ b/spec/requests/spree/api/stock_transfers_controller_spec.rb @@ -1,7 +1,11 @@ require 'spec_helper' +require 'spree/api/testing_support/setup' +require 'spree/api/testing_support/helpers' module Spree describe Api::StockTransfersController do + extend Spree::Api::TestingSupport::Setup + include Spree::Api::TestingSupport::Helpers let!(:stock_transfer) { create(:stock_transfer_with_items) } let(:transfer_item) { stock_transfer.transfer_items.first } diff --git a/spec/requests/spree/api/transfer_items_controller_spec.rb b/spec/requests/spree/api/transfer_items_controller_spec.rb index d1f3b3d..69ba85b 100644 --- a/spec/requests/spree/api/transfer_items_controller_spec.rb +++ b/spec/requests/spree/api/transfer_items_controller_spec.rb @@ -1,7 +1,11 @@ require 'spec_helper' +require 'spree/api/testing_support/setup' +require 'spree/api/testing_support/helpers' module Spree describe Api::TransferItemsController do + extend Spree::Api::TestingSupport::Setup + include Spree::Api::TestingSupport::Helpers let!(:stock_transfer) { create(:stock_transfer_with_items) } let(:transfer_item) { stock_transfer.transfer_items.first } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ae62348 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,23 @@ +if ENV['COVERAGE'] + require "simplecov" + SimpleCov.start "rails" +end + +ENV["RAILS_ENV"] ||= "test" + +require File.expand_path("../dummy/config/environment.rb", __FILE__) + +require 'rails-controller-testing' +require 'solidus_support/extension/feature_helper' + +require 'spree/api/testing_support/helpers' +require 'cancan/matchers' +require 'rspec/active_model/mocks' + +Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f } + +RSpec.configure do |config| + config.infer_spec_type_from_file_location! + + FactoryBot.find_definitions +end diff --git a/spec/support/dummy_ability.rb b/spec/support/dummy_ability.rb new file mode 100644 index 0000000..00c34dc --- /dev/null +++ b/spec/support/dummy_ability.rb @@ -0,0 +1,5 @@ +require 'cancan' + +class DummyAbility + include CanCan::Ability +end diff --git a/spec/support/working_factories.rb b/spec/support/working_factories.rb new file mode 100644 index 0000000..c676eef --- /dev/null +++ b/spec/support/working_factories.rb @@ -0,0 +1,13 @@ +RSpec.shared_examples_for 'a working factory' do + it "builds successfully" do + expect(build(factory)).to be_a(factory_class) + end + + it "creates successfully" do + expect(create(factory)).to be_a(factory_class) + end + + it "is creates a valid record" do + expect(create(factory)).to be_valid + end +end