Port halo/spree_digital to Spree version 2.0.0. Move factories to the correct place (factories.rb) so it can be used/overriden by other modules.
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
module SpreeDigital
|
||||
module Generators
|
||||
class InstallGenerator < Rails::Generators::Base
|
||||
|
||||
# def add_javascripts
|
||||
# append_file "app/assets/javascripts/store/all.js", "//= require store/spree_digital\n"
|
||||
# append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_digital\n"
|
||||
# end
|
||||
|
||||
# def add_stylesheets
|
||||
# inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_digital\n",
|
||||
# :before => /\*\//, :verbose => true
|
||||
# inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_digital\n",
|
||||
# :before => /\*\//, :verbose => true
|
||||
# end
|
||||
|
||||
|
||||
class_option :auto_run_migrations, :type => :boolean, :default => false
|
||||
|
||||
def add_javascripts
|
||||
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_digital\n"
|
||||
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_digital\n"
|
||||
end
|
||||
|
||||
def add_stylesheets
|
||||
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_digital\n", :before => /\*\//, :verbose => true
|
||||
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_digital\n", :before => /\*\//, :verbose => true
|
||||
end
|
||||
|
||||
def add_migrations
|
||||
run 'bundle exec rake railties:install:migrations FROM=spree_digital'
|
||||
end
|
||||
|
||||
|
||||
def run_migrations
|
||||
res = ask "Would you like to run the migrations now? [Y/n]"
|
||||
if res == "" || res.downcase == "y"
|
||||
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!"
|
||||
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
module SpreeDigital
|
||||
class Engine < Rails::Engine
|
||||
require 'spree/core'
|
||||
isolate_namespace Spree
|
||||
engine_name 'spree_digital'
|
||||
|
||||
config.autoload_paths += %W(#{config.root}/lib)
|
||||
|
||||
# use rspec for tests
|
||||
config.generators do |g|
|
||||
g.test_framework :rspec
|
||||
end
|
||||
|
||||
initializer "spree.spree_digital.preferences", :after => "spree.environment" do |app|
|
||||
Spree::DigitalConfiguration = Spree::SpreeDigitalConfiguration.new
|
||||
end
|
||||
@@ -11,10 +18,10 @@ module SpreeDigital
|
||||
initializer "spree.register.digital_shipping", :after => 'spree.register.calculators' do |app|
|
||||
app.config.spree.calculators.shipping_methods << Spree::Calculator::DigitalDelivery
|
||||
end
|
||||
|
||||
|
||||
def self.activate
|
||||
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
|
||||
Rails.application.config.cache_classes ? require(c) : load(c)
|
||||
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
||||
Rails.configuration.cache_classes ? require(c) : load(c)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
FactoryGirl.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:
|
||||
# require 'spree_digital/factories'
|
||||
|
||||
factory :digital, :class => Spree::Digital do |f|
|
||||
# TODO good to assign variant association if no association is manually defined
|
||||
# f.variant { |p| p.association(:variant) }
|
||||
|
||||
attachment_content_type 'application/octet-stream'
|
||||
attachment_file_name 'a_great_book.epub'
|
||||
end
|
||||
|
||||
factory :digital_link, :class => Spree::DigitalLink do |f|
|
||||
f.digital { |p| p.association(:digital) }
|
||||
f.line_item { |p| p.association(:line_item) }
|
||||
end
|
||||
|
||||
factory :digital_shipping_calculator, class: Spree::Calculator::DigitalDelivery do |c|
|
||||
after_create { |c| c.set_preference(:amount, 0) }
|
||||
end
|
||||
|
||||
factory :digital_shipping_method, parent: :shipping_method do |f|
|
||||
name "Digital Delivery"
|
||||
calculator { FactoryGirl.build :digital_shipping_calculator }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user