diff options
| author | Robert | 2017-12-15 08:24:24 +0100 |
|---|---|---|
| committer | Robert | 2017-12-15 08:32:30 +0100 |
| commit | 443de38df52143f72d97308c28ac68f99e009757 (patch) | |
| tree | 376521ea3e78070c3548c622a878bba26c124cb5 | |
| parent | b6067ba25bff1dc95975be49e3f9a02a5932202a (diff) | |
| download | chouette-core-443de38df52143f72d97308c28ac68f99e009757.tar.bz2 | |
Fixes: #5281@1.2h; View specs and minor CR change from #50065281-workbench-import-structural-bug-reading-zip
- CR change from #5006, severity of zip file messages :warning -> :error
- View specs for showing import_messages
| -rw-r--r-- | app/views/imports/_import_messages.html.slim | 9 | ||||
| -rw-r--r-- | app/workers/workbench_import_worker/object_state_updater.rb | 4 | ||||
| -rw-r--r-- | spec/factories/import_messages.rb | 12 | ||||
| -rw-r--r-- | spec/helpers/common_helper_spec.rb | 8 | ||||
| -rw-r--r-- | spec/support/referential.rb | 1 | ||||
| -rw-r--r-- | spec/views/companies/edit.html.erb_spec.rb | 1 | ||||
| -rw-r--r-- | spec/views/imports/show.html.slim_spec.rb | 42 | ||||
| -rw-r--r-- | spec/views/vehicle_journeys/new.html.erb_spec.rb | 1 |
8 files changed, 66 insertions, 12 deletions
diff --git a/app/views/imports/_import_messages.html.slim b/app/views/imports/_import_messages.html.slim index 7c3528184..9ab9226f7 100644 --- a/app/views/imports/_import_messages.html.slim +++ b/app/views/imports/_import_messages.html.slim @@ -1,11 +1,10 @@ - if import_messages.any? - dl - - import_messages.each do | import_message | - .error_message - dt + dl#import_messages + - import_messages.each do | import_message | + dt.import_message = import_message.criticity - dd + dd.import_message = t( ['import_messages', 'compliance_check_messages', import_message.message_key].join('.'), string_keys_to_symbols(import_message.message_attributes)) diff --git a/app/workers/workbench_import_worker/object_state_updater.rb b/app/workers/workbench_import_worker/object_state_updater.rb index e9cc081b7..67bdc0654 100644 --- a/app/workers/workbench_import_worker/object_state_updater.rb +++ b/app/workers/workbench_import_worker/object_state_updater.rb @@ -14,7 +14,7 @@ class WorkbenchImportWorker def update_foreign_lines entry return if entry.foreign_lines.empty? workbench_import.messages.create( - criticity: :warning, + criticity: :error, message_key: 'foreign_lines_in_referential', message_attributes: { 'source_filename' => workbench_import.file.file.file, @@ -25,7 +25,7 @@ class WorkbenchImportWorker def update_spurious entry return if entry.spurious.empty? workbench_import.messages.create( - criticity: :warning, + criticity: :error, message_key: 'inconsistent_zip_file', message_attributes: { 'source_filename' => workbench_import.file.file.file, diff --git a/spec/factories/import_messages.rb b/spec/factories/import_messages.rb index 75f80566c..5d936679a 100644 --- a/spec/factories/import_messages.rb +++ b/spec/factories/import_messages.rb @@ -3,5 +3,17 @@ FactoryGirl.define do association :import association :resource, factory: :import_resource criticity :info + + factory :corrupt_zip_file do + message_key 'corrupt_zip_file' + message_attributes({ source_filename: 'political file' }) + criticity :error + end + + factory :inconsistent_zip_file do + message_key 'inconsistent_zip_file' + message_attributes({ source_filename: 'robert talking', spurious_dirs: %w{dogs and cats}.join }) + criticity :warning + end end end diff --git a/spec/helpers/common_helper_spec.rb b/spec/helpers/common_helper_spec.rb index 186c4184e..1ffdc5bab 100644 --- a/spec/helpers/common_helper_spec.rb +++ b/spec/helpers/common_helper_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CommonHelper do Object.new.extend( described_class ) end - describe 'string_keys_to_symbols' do + describe 'string_keys_to_symbols' do context 'nullpotency on symbol keys' do it { expect(subject.string_keys_to_symbols({})).to eq({}) } it do @@ -14,9 +14,9 @@ RSpec.describe CommonHelper do end end - context 'changing string keys' do + context 'changing string keys' do it { expect(subject.string_keys_to_symbols('alpha' => 100)).to eq(alpha: 100) } - + it do expect( subject.string_keys_to_symbols('a' => 10, b: 20) ) .to eq(a: 10, b: 20) @@ -30,7 +30,7 @@ RSpec.describe CommonHelper do context 'keys, not values, are changed' do it do expect(subject.string_keys_to_symbols(a: 'a', 'b' => 'b', 'c' => :c)) - .to eq(a: 'a', b: 'b', c: :c) + .to eq(a: 'a', b: 'b', c: :c) end end diff --git a/spec/support/referential.rb b/spec/support/referential.rb index b615491da..7f56e5143 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -29,7 +29,6 @@ module ReferentialHelper end end - end end diff --git a/spec/views/companies/edit.html.erb_spec.rb b/spec/views/companies/edit.html.erb_spec.rb index 8aaf705ab..b85b9aa8b 100644 --- a/spec/views/companies/edit.html.erb_spec.rb +++ b/spec/views/companies/edit.html.erb_spec.rb @@ -9,6 +9,7 @@ describe "/companies/edit", :type => :view do describe "form" do it "should render input for name" do render + require 'pry'; binding.pry expect(rendered).to have_selector("form") do with_tag "input[type=text][name='company[name]'][value=?]", company.name end diff --git a/spec/views/imports/show.html.slim_spec.rb b/spec/views/imports/show.html.slim_spec.rb new file mode 100644 index 000000000..f30202231 --- /dev/null +++ b/spec/views/imports/show.html.slim_spec.rb @@ -0,0 +1,42 @@ +RSpec.describe '/imports/show', type: :view do + let(:workbench){ create :workbench } + let(:workbench_import){ create :workbench_import, workbench: workbench } + let!( :messages ) {[ + create(:corrupt_zip_file, import: workbench_import), + create(:inconsistent_zip_file, import: workbench_import), + ]} + + + before do + assign :import, workbench_import.decorate( context: {workbench: workbench} ) + render + end + + it 'shows the correct record...' do + # ... zip file name + expect(rendered).to have_selector('.dl-def') do + with_text workbench_import.file + end + + # ... messages + messages.each do | message | + # require 'htmlbeautifier' + # b = HtmlBeautifier.beautify(rendered, indent: ' ') + # require 'pry'; binding.pry + expect(rendered).to have_selector('dl#import_messages dt.import_message') do + with_text message.criticity + end + expect(rendered).to have_selector('dl#import_messages dd.import_message') do + with_text rendered_message( message ) + end + end + end + + + def rendered_message message + Object.new.extend(CommonHelper).tap do |helper| + return I18n.t(message.message_key, helper.string_keys_to_symbols( message.message_attributes )) + end + end + +end diff --git a/spec/views/vehicle_journeys/new.html.erb_spec.rb b/spec/views/vehicle_journeys/new.html.erb_spec.rb index 546e89ac8..40b7fb049 100644 --- a/spec/views/vehicle_journeys/new.html.erb_spec.rb +++ b/spec/views/vehicle_journeys/new.html.erb_spec.rb @@ -9,6 +9,7 @@ describe "/vehicle_journeys/new", :type => :view do it "renders _form" do render + require 'pry'; binding.pry expect(view).to render_template(:partial => "_form") end |
