aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/imports_controller.rb6
-rw-r--r--app/models/import.rb13
-rw-r--r--lib/tasks/demo.rake4
-rw-r--r--spec/controllers/imports_controller_spec.rb19
4 files changed, 29 insertions, 13 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 06017da7d..31af06c7d 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -15,6 +15,12 @@ class ImportsController < ChouetteController
end
end
+ def create_resource( import )
+ if import.save
+ import.delayed_import
+ end
+ end
+
protected
def available_imports
diff --git a/app/models/import.rb b/app/models/import.rb
index e0c95f911..629d54a42 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -6,7 +6,6 @@ class Import < ActiveRecord::Base
validates_inclusion_of :status, :in => %w{ pending completed failed }
- attr_accessor :background
attr_accessor :resources
attr_accessor :loader
@@ -73,19 +72,9 @@ class Import < ActiveRecord::Base
end
end
- after_create :delayed_import
def delayed_import
save_resources
- if import_in_background?
- delay.import
- else
- # do not call self.inport
- import
- end
- end
-
- def import_in_background?
- return background.nil? || background
+ delay.import
end
@@root = "#{Rails.root}/tmp/imports"
diff --git a/lib/tasks/demo.rake b/lib/tasks/demo.rake
index fe26ca9d1..7d964b894 100644
--- a/lib/tasks/demo.rake
+++ b/lib/tasks/demo.rake
@@ -14,7 +14,9 @@ namespace :demo do
referential = organisation.referentials.create( :name => "Tatrobus", :slug => "tatrobus", :prefix => "TAT")
resource = Rack::Test::UploadedFile.new( Rails.application.config.demo_data, 'application/zip', false)
- import_instance = referential.imports.create( :resources => resource, :referential_id => referential.id, :background => false)
+ import_instance = referential.imports.create( :resources => resource, :referential_id => referential.id)
+ import_instance.save_resources
+ import_instance.import
puts "Restore demo environment complete"
end
end
diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb
index e7a49a8e8..9c5f2e641 100644
--- a/spec/controllers/imports_controller_spec.rb
+++ b/spec/controllers/imports_controller_spec.rb
@@ -11,6 +11,25 @@ describe ImportsController do
end
end
+ describe "POST 'create'" do
+ before(:each) do
+ post :create,
+ :referential_id => referential.id,
+ :import => { :resources => Rack::Test::UploadedFile.new( "tmp/demo.zip", 'application/zip', false)}
+ end
+
+ it "assigns import.referential as @referential" do
+ assigns[:import].referential.should == referential
+ end
+
+ it "assigns referential as @referential" do
+ assigns[:referential].should == referential
+ end
+ it "shoud redirect to imports" do
+ response.should redirect_to referential_imports_path(referential)
+ end
+ end
+
describe "GET 'index'" do
it "returns http success" do
pending