aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRobert2017-12-15 08:24:24 +0100
committerRobert2017-12-15 08:32:30 +0100
commit443de38df52143f72d97308c28ac68f99e009757 (patch)
tree376521ea3e78070c3548c622a878bba26c124cb5 /spec
parentb6067ba25bff1dc95975be49e3f9a02a5932202a (diff)
downloadchouette-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
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/import_messages.rb12
-rw-r--r--spec/helpers/common_helper_spec.rb8
-rw-r--r--spec/support/referential.rb1
-rw-r--r--spec/views/companies/edit.html.erb_spec.rb1
-rw-r--r--spec/views/imports/show.html.slim_spec.rb42
-rw-r--r--spec/views/vehicle_journeys/new.html.erb_spec.rb1
6 files changed, 60 insertions, 5 deletions
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