aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorZog2018-03-08 11:46:20 +0100
committerZog2018-03-12 12:00:14 +0100
commita4a075f5eec935dd6a0dbf0a861b6ada13b1dcbc (patch)
treeb046d69937ce998d918a7a4bf5a3e2e418961fa1 /spec
parentdb15dc6158939d2577ccd53aac66a283ce4f3338 (diff)
downloadchouette-core-a4a075f5eec935dd6a0dbf0a861b6ada13b1dcbc.tar.bz2
Refs #6133; Add options on the Exports, and forward them tu the UX
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/exports_controller_spec.rb65
-rw-r--r--spec/models/export/netex_export_spec.rb19
-rw-r--r--spec/models/export/workbench_export_spec.rb10
-rw-r--r--spec/models/import/netex_import_spec.rb1
4 files changed, 85 insertions, 10 deletions
diff --git a/spec/controllers/exports_controller_spec.rb b/spec/controllers/exports_controller_spec.rb
index a1a40d571..a070cfb1f 100644
--- a/spec/controllers/exports_controller_spec.rb
+++ b/spec/controllers/exports_controller_spec.rb
@@ -18,15 +18,62 @@ RSpec.describe ExportsController, :type => :controller do
end
describe "POST #create" do
- it "displays a flash message" do
- post :create, workbench_id: workbench.id,
- export: {
- name: 'Offre'
- }
-
- expect(controller).to set_flash[:notice].to(
- I18n.t('flash.exports.create.notice')
- )
+ let(:params){ {name: "foo"} }
+ let(:request){ post :create, workbench_id: workbench.id, export: params }
+ it 'should create no objects' do
+ expect{request}.to_not change{Export::Base.count}
+ end
+
+ context "with full params" do
+ let(:params){{
+ name: "foo",
+ type: "Export::Netex"
+ }}
+
+ it 'should be successful' do
+ expect{request}.to change{Export::Base.count}.by(1)
+ end
+
+ it "displays a flash message" do
+ request
+ expect(controller).to set_flash[:notice].to(
+ I18n.t('flash.exports.create.notice')
+ )
+ end
+ end
+
+ context "with missing options" do
+ let(:params){{
+ name: "foo",
+ type: "Export::Workbench"
+ }}
+
+ it 'should be unsuccessful' do
+ expect{request}.to change{Export::Base.count}.by(0)
+ end
+ end
+
+ context "with all options" do
+ let(:params){{
+ name: "foo",
+ type: "Export::Workbench",
+ timelapse: 90
+ }}
+
+ it 'should be successful' do
+ expect{request}.to change{Export::Base.count}.by(1)
+ end
+ end
+
+ context "with wrong type" do
+ let(:params){{
+ name: "foo",
+ type: "Export::Foo"
+ }}
+
+ it 'should be unsuccessful' do
+ expect{request}.to raise_error ActiveRecord::SubclassNotFound
+ end
end
end
end
diff --git a/spec/models/export/netex_export_spec.rb b/spec/models/export/netex_export_spec.rb
new file mode 100644
index 000000000..d9cccd6ad
--- /dev/null
+++ b/spec/models/export/netex_export_spec.rb
@@ -0,0 +1,19 @@
+RSpec.describe Export::Netex, type: [:model, :with_commit] do
+
+ let( :boiv_iev_uri ){ URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/exporter/new?id=#{subject.id}")}
+
+ before do
+ allow(Thread).to receive(:new).and_yield
+ end
+
+ context 'with referential' do
+ subject{ build( :netex_export, id: random_int ) }
+
+ it 'will trigger the Java API' do
+ with_stubbed_request(:get, boiv_iev_uri) do |request|
+ with_commit{ subject.save! }
+ expect(request).to have_been_requested
+ end
+ end
+ end
+end
diff --git a/spec/models/export/workbench_export_spec.rb b/spec/models/export/workbench_export_spec.rb
new file mode 100644
index 000000000..1b2e81aa4
--- /dev/null
+++ b/spec/models/export/workbench_export_spec.rb
@@ -0,0 +1,10 @@
+RSpec.describe Export::Workbench, type: [:model, :with_commit] do
+ it { should validate_presence_of(:timelapse) }
+
+ it "should set options" do
+ expect(Export::Workbench.options).to have_key :timelapse
+ expect(Export::Workbench.options[:timelapse][:required]).to be_truthy
+ expect(Export::Workbench.options[:timelapse][:default_value]).to eq 90
+ expect(Export::Workbench.options[:timelapse][:type]).to eq :integer
+ end
+end
diff --git a/spec/models/import/netex_import_spec.rb b/spec/models/import/netex_import_spec.rb
index 9b9f50117..6424fbfe1 100644
--- a/spec/models/import/netex_import_spec.rb
+++ b/spec/models/import/netex_import_spec.rb
@@ -2,7 +2,6 @@ RSpec.describe Import::Netex, type: [:model, :with_commit] do
let( :boiv_iev_uri ){ URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{subject.id}")}
-
before do
allow(Thread).to receive(:new).and_yield
end