Merge pull request #11 from iloveitaly/spree-1.0
Spree 1.0 Compatibility + Passing Tests
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -7,5 +7,6 @@
|
||||
tmp
|
||||
nbproject
|
||||
*.swp
|
||||
spec/test_app
|
||||
*.tmproj
|
||||
spec/dummy
|
||||
*.tmproj
|
||||
Gemfile.lock
|
||||
|
||||
47
Gemfile
47
Gemfile
@@ -1,35 +1,16 @@
|
||||
source 'http://rubygems.org'
|
||||
|
||||
#gem 'spree_core', :path => '../spree/core'
|
||||
#gem 'spree_digital', :path => 'spree_digital'
|
||||
#gem "sqlite3-ruby"
|
||||
#
|
||||
#group :test do
|
||||
# gem 'rspec-rails', '= 2.5.0'
|
||||
# gem 'factory_girl', '= 1.3.3'
|
||||
# gem 'factory_girl_rails', '= 1.0.1'
|
||||
# gem 'rcov'
|
||||
# gem 'shoulda'
|
||||
# gem 'faker'
|
||||
# if RUBY_VERSION < "1.9"
|
||||
# gem "ruby-debug"
|
||||
# else
|
||||
# gem "ruby-debug19"
|
||||
# end
|
||||
#end
|
||||
#
|
||||
#group :cucumber do
|
||||
# gem 'cucumber-rails'
|
||||
# gem 'database_cleaner', '= 0.6.7.RC'
|
||||
# gem 'nokogiri'
|
||||
# gem 'capybara', '= 0.4.1.2'
|
||||
# gem 'factory_girl', '= 1.3.3'
|
||||
# gem 'factory_girl_rails', '= 1.0.1'
|
||||
# gem 'faker'
|
||||
# gem 'launchy'
|
||||
# if RUBY_VERSION < "1.9"
|
||||
# gem "ruby-debug"
|
||||
# else
|
||||
# gem "ruby-debug19"
|
||||
# end
|
||||
#end
|
||||
group :test do
|
||||
# without ffaker in test it wont init
|
||||
# https://github.com/spree/spree/pull/833
|
||||
gem 'ffaker'
|
||||
gem 'shoulda-matchers'
|
||||
gem 'guard-rspec'
|
||||
|
||||
if RUBY_PLATFORM.downcase.include? "darwin"
|
||||
gem 'rb-fsevent'
|
||||
gem 'growl'
|
||||
end
|
||||
end
|
||||
|
||||
gemspec
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
18
Guardfile
Normal file
18
Guardfile
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
guard 'rspec', :version => 2 do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
||||
# Rails example
|
||||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
||||
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
||||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
||||
watch('config/routes.rb') { "spec/routing" }
|
||||
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
||||
# Capybara request specs
|
||||
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
||||
end
|
||||
|
||||
66
Rakefile
66
Rakefile
@@ -1,31 +1,17 @@
|
||||
require 'rubygems'
|
||||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rake/packagetask'
|
||||
require 'rake/gempackagetask'
|
||||
require 'rubygems/package_task'
|
||||
require 'rspec/core/rake_task'
|
||||
require 'spree/core/testing_support/common_rake'
|
||||
|
||||
gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
|
||||
if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
|
||||
require 'bundler'
|
||||
ENV['BUNDLE_GEMFILE'] = gemfile
|
||||
Bundler.setup
|
||||
RSpec::Core::RakeTask.new
|
||||
|
||||
require 'rspec'
|
||||
require 'rspec/core/rake_task'
|
||||
RSpec::Core::RakeTask.new
|
||||
|
||||
require 'cucumber/rake/task'
|
||||
Cucumber::Rake::Task.new do |t|
|
||||
t.cucumber_opts = %w{--format progress}
|
||||
end
|
||||
end
|
||||
|
||||
desc "Default Task"
|
||||
task :default => [:spec, :cucumber ]
|
||||
task :default => [:spec]
|
||||
|
||||
spec = eval(File.read('spree_digital.gemspec'))
|
||||
|
||||
Rake::GemPackageTask.new(spec) do |p|
|
||||
Gem::PackageTask.new(spec) do |p|
|
||||
p.gem_spec = spec
|
||||
end
|
||||
|
||||
@@ -36,40 +22,18 @@ task :release => :package do
|
||||
Rake::Task['gem:push'].invoke
|
||||
end
|
||||
|
||||
desc "Default Task"
|
||||
task :default => [ :spec ]
|
||||
|
||||
desc "Regenerates a rails 3 app for testing"
|
||||
task :test_app do
|
||||
require '../spree/lib/generators/spree/test_app_generator'
|
||||
class SpreeDigitalTestAppGenerator < Spree::Generators::TestAppGenerator
|
||||
|
||||
def install_gems
|
||||
inside "test_app" do
|
||||
run 'rake spree_core:install'
|
||||
run 'rake spree_digital:install'
|
||||
end
|
||||
ENV['LIB_NAME'] = 'spree_digital'
|
||||
|
||||
require File.join `bundle show spree_core`.chomp, 'lib/generators/spree/dummy/dummy_generator.rb'
|
||||
Spree::DummyGenerator.class_eval do
|
||||
def test_dummy_add_digital
|
||||
# pulled from: http://jumph4x.net/post/20067515804/testing-spree-1-0-x-extensions-w-other-extension
|
||||
puts "Installing #{ENV['LIB_NAME']} migrations [required for testing]"
|
||||
directory File.join(`bundle show #{ENV['LIB_NAME']}`.chomp, 'db', 'migrate'), File.join(dummy_path, 'db')
|
||||
end
|
||||
|
||||
def migrate_db
|
||||
run_migrations
|
||||
end
|
||||
|
||||
protected
|
||||
def full_path_for_local_gems
|
||||
<<-gems
|
||||
gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
|
||||
gem 'spree_digital', :path => \'#{File.dirname(__FILE__)}\'
|
||||
gems
|
||||
end
|
||||
|
||||
end
|
||||
SpreeDigitalTestAppGenerator.start
|
||||
end
|
||||
|
||||
namespace :test_app do
|
||||
desc 'Rebuild test and cucumber databases'
|
||||
task :rebuild_dbs do
|
||||
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
|
||||
end
|
||||
Rake::Task['common:test_app'].invoke
|
||||
end
|
||||
|
||||
10
Versionfile
10
Versionfile
@@ -1,8 +1,2 @@
|
||||
# This file is used to designate compatibilty with different versions of Spree
|
||||
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
|
||||
|
||||
# Currently this works with these both:
|
||||
|
||||
"0.60.x" => { :branch => "master" }
|
||||
"0.50.x" => { :branch => "master" }
|
||||
"0.7.x" => { :ref => "eddaea63959586d123007cbca3be5bf9c5edb1a7" }
|
||||
"0.7.x" => { :ref => "eddaea63959586d123007cbca3be5bf9c5edb1a7" }
|
||||
"1.0.x" => { :branch => "master" }
|
||||
|
||||
1
app/assets/javascripts/admin/spree_digital.js
Normal file
1
app/assets/javascripts/admin/spree_digital.js
Normal file
@@ -0,0 +1 @@
|
||||
//= require admin/spree_core
|
||||
1
app/assets/javascripts/store/spree_digital.js
Normal file
1
app/assets/javascripts/store/spree_digital.js
Normal file
@@ -0,0 +1 @@
|
||||
//= require store/spree_core
|
||||
3
app/assets/stylesheets/admin/spree_digital.css
Normal file
3
app/assets/stylesheets/admin/spree_digital.css
Normal file
@@ -0,0 +1,3 @@
|
||||
/*
|
||||
*= require admin/spree_core
|
||||
*/
|
||||
3
app/assets/stylesheets/store/spree_digital.css
Normal file
3
app/assets/stylesheets/store/spree_digital.css
Normal file
@@ -0,0 +1,3 @@
|
||||
/*
|
||||
*= require store/spree_core
|
||||
*/
|
||||
@@ -3,7 +3,10 @@ module Spree
|
||||
|
||||
belongs_to :digital
|
||||
belongs_to :line_item
|
||||
|
||||
|
||||
validates_length_of :secret, :is => 30
|
||||
validates :digital, :presence => true
|
||||
|
||||
before_validation :set_defaults, :on => :create
|
||||
|
||||
# Can this link stil be used? It is valid if it's less than 24 hours old and was not accessed more than 3 times
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Spree::LineItem.class_eval do
|
||||
|
||||
has_many :digital_links
|
||||
has_many :digital_links, :dependent => :destroy
|
||||
|
||||
after_save :create_digital_links, :if => :digital?
|
||||
|
||||
@@ -14,6 +14,7 @@ Spree::LineItem.class_eval do
|
||||
# Create the download link for this item if it is digital.
|
||||
def create_digital_links
|
||||
digital_links.delete_all
|
||||
|
||||
self.quantity.times do
|
||||
digital_links.create!(:digital => variant.digital)
|
||||
end
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
class SpreeDigitalHooks < Spree::ThemeSupport::HookListener
|
||||
Deface::Override.new(:virtual_path => "spree/admin/shared/_product_tabs",
|
||||
:name => "converted_admin_product_tabs_986577829",
|
||||
Deface::Override.new(:virtual_path => "spree/admin/shared/_product_tabs",
|
||||
:name => "add_digital_versions_to_admin_product_tabs",
|
||||
:insert_bottom => "[data-hook='admin_product_tabs'], #admin_product_tabs[data-hook]",
|
||||
:text => " <li<%== ' class=\"active\"' if current == \"Digital Versions\" %>>
|
||||
<%= link_to t(\"digital_versions\"), admin_product_digitals_path(@product) %>
|
||||
</li>
|
||||
",
|
||||
:disabled => false)
|
||||
end
|
||||
31
lib/generators/spree_digital/install/install_generator.rb
Normal file
31
lib/generators/spree_digital/install/install_generator.rb
Normal file
@@ -0,0 +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
|
||||
|
||||
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 'bundle exec rake db:migrate'
|
||||
else
|
||||
puts "Skipping rake db:migrate, don't forget to run it!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,17 +1,2 @@
|
||||
require 'spree_core'
|
||||
require 'spree_digital_hooks'
|
||||
|
||||
module SpreeDigital
|
||||
class Engine < Rails::Engine
|
||||
|
||||
config.autoload_paths += %W(#{config.root}/lib)
|
||||
|
||||
def self.activate
|
||||
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
||||
Rails.env.production? ? require(c) : load(c)
|
||||
end
|
||||
end
|
||||
|
||||
config.to_prepare &method(:activate).to_proc
|
||||
end
|
||||
end
|
||||
require 'spree_digital/engine'
|
||||
|
||||
24
lib/spree_digital/engine.rb
Normal file
24
lib/spree_digital/engine.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
module SpreeDigital
|
||||
class Engine < Rails::Engine
|
||||
engine_name 'spree_digital'
|
||||
|
||||
config.autoload_paths += %W(#{config.root}/lib)
|
||||
|
||||
# Use RSpec for tests
|
||||
config.generators do |g|
|
||||
g.test_framework :rspec
|
||||
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)
|
||||
end
|
||||
|
||||
Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
|
||||
Rails.application.config.cache_classes ? require(c) : load(c)
|
||||
end
|
||||
end
|
||||
|
||||
config.to_prepare &method(:activate).to_proc
|
||||
end
|
||||
end
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace :spree_digital do
|
||||
|
||||
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
||||
task :install do
|
||||
Rake::Task['spree_digital:install:migrations'].invoke
|
||||
end
|
||||
|
||||
namespace :install do
|
||||
|
||||
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
||||
task :migrations do
|
||||
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
||||
destination = File.join(Rails.root, 'db')
|
||||
Spree::FileUtilz.mirror_files(source, destination)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1 +0,0 @@
|
||||
# add custom rake tasks here
|
||||
@@ -1,3 +1,3 @@
|
||||
Factory.define :digital do |f|
|
||||
Factory.define :digital, :class => Spree::Digital do |f|
|
||||
f.variant { |p| p.association(:variant) }
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
Factory.define :digital_link do |f|
|
||||
Factory.define :digital_link, :class => Spree::DigitalLink do |f|
|
||||
f.digital { |p| p.association(:digital) }
|
||||
f.line_item { |p| p.association(:line_item) }
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe DigitalLink do
|
||||
describe Spree::DigitalLink do
|
||||
|
||||
context 'validation' do
|
||||
it { should belong_to(:digital) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe Digital do
|
||||
describe Spree::Digital do
|
||||
|
||||
context 'validation' do
|
||||
it { should belong_to(:variant) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe LineItem do
|
||||
describe Spree::LineItem do
|
||||
|
||||
context "#save" do
|
||||
it "should create one link for a single digital Variant" do
|
||||
@@ -17,6 +17,7 @@ describe LineItem do
|
||||
links = digital_variant.digital.digital_links
|
||||
links.all.size.should == 5
|
||||
links.each { |link| link.line_item.should == line_item }
|
||||
|
||||
# quantity update
|
||||
line_item.quantity = 8
|
||||
line_item.save
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe Order do
|
||||
describe Spree::Order do
|
||||
|
||||
context 'validation' do
|
||||
it { should have_valid_factory(:order) }
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
require File.expand_path("../factories", __FILE__)
|
||||
# Configure Rails Environment
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
|
||||
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
||||
|
||||
|
||||
########################################################################
|
||||
# NOTE: The rest of file is the same as spree/core/spec/spec_helper.rb #
|
||||
########################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
||||
# from the project root directory.
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.expand_path("../test_app/config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
|
||||
# Requires supporting files with custom matchers and macros, etc,
|
||||
# in ./support/ and its subdirectories.
|
||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
||||
# 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 }
|
||||
|
||||
require 'spree_core/testing_support/factories'
|
||||
# Requires factories defined in spree_core
|
||||
require 'spree/core/testing_support/factories'
|
||||
|
||||
RSpec.configure do |config|
|
||||
# == Mock Framework
|
||||
@@ -34,28 +22,20 @@ RSpec.configure do |config|
|
||||
# config.mock_with :rr
|
||||
config.mock_with :rspec
|
||||
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
#config.include Devise::TestHelpers, :type => :controller
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, comment the following line or assign false
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
end
|
||||
|
||||
@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
|
||||
require File.expand_path("../factories", __FILE__)
|
||||
|
||||
PAYMENT_STATES = Payment.state_machine.states.keys unless defined? PAYMENT_STATES
|
||||
SHIPMENT_STATES = Shipment.state_machine.states.keys unless defined? SHIPMENT_STATES
|
||||
ORDER_STATES = Order.state_machine.states.keys unless defined? ORDER_STATES
|
||||
|
||||
# Usage:
|
||||
#
|
||||
# context "factory" do
|
||||
# it { should have_valid_factory(:address) }
|
||||
# end
|
||||
# not sure if this really adds anything, but this existed in the intial version of the spree_digital rspec testing
|
||||
RSpec::Matchers.define :have_valid_factory do |factory_name|
|
||||
match do |model|
|
||||
Factory(factory_name).new_record?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.name = 'spree_digital'
|
||||
s.version = '0.60.99'
|
||||
s.version = '1.0.0'
|
||||
s.summary = ''
|
||||
s.description = 'This gem is supposed to be used in connection with spree_core. It was tested with spree_core 0.66.99 but it might work with newer versions as well.'
|
||||
s.author = 'funkensturm.'
|
||||
@@ -11,5 +11,13 @@ Gem::Specification.new do |s|
|
||||
s.require_path = 'lib'
|
||||
s.requirements << 'none'
|
||||
s.required_ruby_version = '>= 1.8.7'
|
||||
s.add_dependency('spree_core')
|
||||
s.add_dependency('spree_core', '~> 1.0.0')
|
||||
|
||||
# test suite
|
||||
s.add_development_dependency 'shoulda-matchers'
|
||||
s.add_development_dependency 'capybara'
|
||||
s.add_development_dependency 'factory_girl'
|
||||
s.add_development_dependency 'ffaker'
|
||||
s.add_development_dependency 'rspec-rails'
|
||||
s.add_development_dependency 'sqlite3'
|
||||
end
|
||||
Reference in New Issue
Block a user