diff --git a/.gitignore b/.gitignore
index dbe7f07..39a875e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,6 @@
tmp
nbproject
*.swp
-spec/test_app
-*.tmproj
\ No newline at end of file
+spec/dummy
+*.tmproj
+Gemfile.lock
diff --git a/Gemfile b/Gemfile
index fef476b..caa8242 100644
--- a/Gemfile
+++ b/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
diff --git a/Gemfile.lock b/Gemfile.lock
deleted file mode 100644
index 87dd97c..0000000
--- a/Gemfile.lock
+++ /dev/null
@@ -1,8 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
diff --git a/Guardfile b/Guardfile
new file mode 100644
index 0000000..2517982
--- /dev/null
+++ b/Guardfile
@@ -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
+
diff --git a/Rakefile b/Rakefile
index e5bd00a..cfc0970 100644
--- a/Rakefile
+++ b/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
diff --git a/Versionfile b/Versionfile
index 6349e42..42e13a1 100644
--- a/Versionfile
+++ b/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" }
\ No newline at end of file
+"0.7.x" => { :ref => "eddaea63959586d123007cbca3be5bf9c5edb1a7" }
+"1.0.x" => { :branch => "master" }
diff --git a/app/assets/javascripts/admin/spree_digital.js b/app/assets/javascripts/admin/spree_digital.js
new file mode 100644
index 0000000..3cfdc27
--- /dev/null
+++ b/app/assets/javascripts/admin/spree_digital.js
@@ -0,0 +1 @@
+//= require admin/spree_core
\ No newline at end of file
diff --git a/app/assets/javascripts/store/spree_digital.js b/app/assets/javascripts/store/spree_digital.js
new file mode 100644
index 0000000..048c5a2
--- /dev/null
+++ b/app/assets/javascripts/store/spree_digital.js
@@ -0,0 +1 @@
+//= require store/spree_core
\ No newline at end of file
diff --git a/app/assets/stylesheets/admin/spree_digital.css b/app/assets/stylesheets/admin/spree_digital.css
new file mode 100644
index 0000000..5ffa536
--- /dev/null
+++ b/app/assets/stylesheets/admin/spree_digital.css
@@ -0,0 +1,3 @@
+/*
+ *= require admin/spree_core
+*/
\ No newline at end of file
diff --git a/app/assets/stylesheets/store/spree_digital.css b/app/assets/stylesheets/store/spree_digital.css
new file mode 100644
index 0000000..88f5eff
--- /dev/null
+++ b/app/assets/stylesheets/store/spree_digital.css
@@ -0,0 +1,3 @@
+/*
+ *= require store/spree_core
+*/
\ No newline at end of file
diff --git a/app/models/spree/digital_link.rb b/app/models/spree/digital_link.rb
index 797d9ba..7304fbb 100644
--- a/app/models/spree/digital_link.rb
+++ b/app/models/spree/digital_link.rb
@@ -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
diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb
index 73bcbfb..8d73a3e 100644
--- a/app/models/spree/line_item_decorator.rb
+++ b/app/models/spree/line_item_decorator.rb
@@ -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
diff --git a/lib/spree_digital_hooks.rb b/app/overrides/add_digital_versions_to_admin_product_tabs.rb
similarity index 64%
rename from lib/spree_digital_hooks.rb
rename to app/overrides/add_digital_versions_to_admin_product_tabs.rb
index 1034edf..08ac92b 100644
--- a/lib/spree_digital_hooks.rb
+++ b/app/overrides/add_digital_versions_to_admin_product_tabs.rb
@@ -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 => "
>
<%= link_to t(\"digital_versions\"), admin_product_digitals_path(@product) %>
",
:disabled => false)
-end
diff --git a/lib/generators/spree_digital/install/install_generator.rb b/lib/generators/spree_digital/install/install_generator.rb
new file mode 100644
index 0000000..b8012b3
--- /dev/null
+++ b/lib/generators/spree_digital/install/install_generator.rb
@@ -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
\ No newline at end of file
diff --git a/lib/spree_digital.rb b/lib/spree_digital.rb
index 146666f..0ee9772 100644
--- a/lib/spree_digital.rb
+++ b/lib/spree_digital.rb
@@ -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'
diff --git a/lib/spree_digital/engine.rb b/lib/spree_digital/engine.rb
new file mode 100644
index 0000000..929ac96
--- /dev/null
+++ b/lib/spree_digital/engine.rb
@@ -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
diff --git a/lib/tasks/install.rake b/lib/tasks/install.rake
deleted file mode 100644
index bb5f853..0000000
--- a/lib/tasks/install.rake
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/lib/tasks/spree_digital.rake b/lib/tasks/spree_digital.rake
deleted file mode 100644
index 2c5c4e2..0000000
--- a/lib/tasks/spree_digital.rake
+++ /dev/null
@@ -1 +0,0 @@
-# add custom rake tasks here
\ No newline at end of file
diff --git a/spec/factories/digital_factory.rb b/spec/factories/digital_factory.rb
index 3c77261..1b029ca 100644
--- a/spec/factories/digital_factory.rb
+++ b/spec/factories/digital_factory.rb
@@ -1,3 +1,3 @@
-Factory.define :digital do |f|
+Factory.define :digital, :class => Spree::Digital do |f|
f.variant { |p| p.association(:variant) }
end
\ No newline at end of file
diff --git a/spec/factories/digital_link_factory.rb b/spec/factories/digital_link_factory.rb
index fea0395..140c644 100644
--- a/spec/factories/digital_link_factory.rb
+++ b/spec/factories/digital_link_factory.rb
@@ -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
\ No newline at end of file
diff --git a/spec/models/digital_link_spec.rb b/spec/models/digital_link_spec.rb
index 1d4d18f..878644c 100644
--- a/spec/models/digital_link_spec.rb
+++ b/spec/models/digital_link_spec.rb
@@ -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) }
diff --git a/spec/models/digital_spec.rb b/spec/models/digital_spec.rb
index 9d7cb41..758d275 100644
--- a/spec/models/digital_spec.rb
+++ b/spec/models/digital_spec.rb
@@ -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) }
diff --git a/spec/models/line_item_spec.rb b/spec/models/line_item_spec.rb
index f0d6c8e..f6b27df 100644
--- a/spec/models/line_item_spec.rb
+++ b/spec/models/line_item_spec.rb
@@ -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
diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb
index 4784f87..83eb072 100644
--- a/spec/models/order_spec.rb
+++ b/spec/models/order_spec.rb
@@ -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) }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index ad92fa0..93c5af0 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -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
\ No newline at end of file
diff --git a/spree_digital.gemspec b/spree_digital.gemspec
index 34d8cc7..c4118bf 100644
--- a/spree_digital.gemspec
+++ b/spree_digital.gemspec
@@ -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
\ No newline at end of file