From 244de985c6c00b6385e9af47f9dec08de1eec6c5 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 29 May 2012 08:57:01 +0200 Subject: Include html_safe an ready? in ApplicationMap#to_html --- spec/views/lines/show.html.erb_spec.rb | 2 +- spec/views/networks/show.html.erb_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 42261005a..f77722672 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -5,7 +5,7 @@ describe "/lines/show" do let!(:referential) { assign :referential, create(:referential) } let!(:line) { assign :line, create(:line) } let!(:routes) { assign :routes, Array.new(2) { create(:route, :line => line) }.paginate } - let!(:map) { assign(:map, mock(:to_html => '
')) } + let!(:map) { assign(:map, mock(:to_html => ''.html_safe)) } it "should render h2 with the line name" do render diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 9c05fe4aa..9c4f34f96 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/networks/show" do let!(:referential) { assign(:referential, create(:referential)) } let!(:network) { assign(:network, create(:network)) } - let!(:map) { assign(:map, mock(:to_html => '')) } + let!(:map) { assign(:map, mock(:to_html => ''.html_safe)) } it "should render h2 with the network name" do render @@ -13,6 +13,7 @@ describe "/networks/show" do it "should display a map with class 'network'" do render + puts rendered rendered.should have_selector("#map") end -- cgit v1.2.3 From ee0f3849cb6a2278783aabb166fb5c2661cdb400 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 29 May 2012 17:08:17 +0200 Subject: Removes explicit ApplicationMap#html_safe --- spec/views/connection_links/show.html.erb_spec.rb | 2 +- spec/views/routes/show.html.erb_spec.rb | 2 +- spec/views/stop_areas/edit.html.erb_spec.rb | 2 +- spec/views/stop_areas/show.html.erb_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/views/connection_links/show.html.erb_spec.rb b/spec/views/connection_links/show.html.erb_spec.rb index 8a03f5339..80d3adfb6 100644 --- a/spec/views/connection_links/show.html.erb_spec.rb +++ b/spec/views/connection_links/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/connection_links/show" do let!(:referential) { assign(:referential, create(:referential)) } let!(:connection_link) { assign(:connection_link, create(:connection_link)) } - let!(:map) { assign(:map, mock(:to_html => '')) } + let!(:map) { assign(:map, mock(:to_html => ''.html_safe)) } it "should render h2 with the connection_link name" do render diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 5fa7485b7..2f39adb9a 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -6,7 +6,7 @@ describe "/routes/show" do let!(:line) { assign :line, create(:line) } let!(:route) { assign :route, create(:route, :line => line) } let!(:stop_points) { assign :stop_points, Array.new(2) { create(:stop_point) }.paginate } - let!(:map) { assign(:map, mock(:to_html => '')) } + let!(:map) { assign(:map, mock(:to_html => ''.html_safe)) } it "should render h2 with the route name" do render diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb index c3b89918d..17e9ca104 100644 --- a/spec/views/stop_areas/edit.html.erb_spec.rb +++ b/spec/views/stop_areas/edit.html.erb_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe "/stop_areas/edit" do let!(:referential) { assign(:referential, create(:referential)) } let!(:stop_area) { assign(:stop_area, create(:stop_area)) } - let!(:map) { assign(:map, mock(:to_html => '')) } + let!(:map) { assign(:map, mock(:to_html => ''.html_safe)) } describe "test" do it "should render h2 with the group name" do diff --git a/spec/views/stop_areas/show.html.erb_spec.rb b/spec/views/stop_areas/show.html.erb_spec.rb index 443a37232..b4be2c5e0 100644 --- a/spec/views/stop_areas/show.html.erb_spec.rb +++ b/spec/views/stop_areas/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/stop_areas/show" do let!(:referential) { assign :referential, create(:referential) } let!(:stop_area) { assign :stop_area, create(:stop_area) } - let!(:map) { assign(:map, mock(:to_html => '')) } + let!(:map) { assign(:map, mock(:to_html => ''.html_safe)) } it "should render h2 with the stop_area name" do render -- cgit v1.2.3 From 0f9cec96c44a1102b0964123d26809cc1e2bab8f Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 30 May 2012 09:47:25 +0200 Subject: Remove a nice puts --- spec/views/networks/show.html.erb_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec') diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 9c4f34f96..08ecdd95d 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -13,7 +13,6 @@ describe "/networks/show" do it "should display a map with class 'network'" do render - puts rendered rendered.should have_selector("#map") end -- cgit v1.2.3 From 7082d66ec221aee194d64a17ab5d21eb2955f419 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 30 May 2012 17:23:18 +0200 Subject: Create and display ImportLogMessages. Refs #39 --- spec/factories.rb | 10 ++++++++++ spec/fixtures/neptune.zip | Bin 0 -> 4904 bytes spec/models/import_log_message_spec.rb | 16 ++++++++++++++++ spec/models/import_spec.rb | 32 +++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/neptune.zip create mode 100644 spec/models/import_log_message_spec.rb (limited to 'spec') diff --git a/spec/factories.rb b/spec/factories.rb index b77102321..c5c1c0ff0 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -11,4 +11,14 @@ FactoryGirl.define do f.password_confirmation "secret" end + factory :import do |f| + f.resources { Rack::Test::UploadedFile.new 'spec/fixtures/neptune.zip', 'application/zip', false } + f.association :referential + end + + factory :import_log_message do |f| + f.association :import + f.sequence(:key) { "key_#{n}" } + end + end diff --git a/spec/fixtures/neptune.zip b/spec/fixtures/neptune.zip new file mode 100644 index 000000000..86b688b51 Binary files /dev/null and b/spec/fixtures/neptune.zip differ diff --git a/spec/models/import_log_message_spec.rb b/spec/models/import_log_message_spec.rb new file mode 100644 index 000000000..dab951255 --- /dev/null +++ b/spec/models/import_log_message_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe ImportLogMessage do + + describe "#attributes" do + + subject { create :import_log_message } + + it "should read json stored in database" do + subject.update_attribute :arguments, { "key" => "value"} + subject.raw_attributes.should == { "key" => "value"}.to_json + end + + end + +end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 734445b8b..f307b59db 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -1,7 +1,37 @@ require 'spec_helper' describe Import do + + subject { create :import } + + RSpec::Matchers.define :be_log_message do |expected| + match do |actual| + actual and expected.all? { |k,v| actual[k.to_s] == v } + end + end - + describe "#import" do + + before(:each) do + subject.stub :loader => mock(:import => true) + end + + it "should create a ImportLogmessage :started when started" do + subject.import + subject.log_messages.first.should be_log_message(:key => "started") + end + + it "should create a ImportLogmessage :completed when completed" do + subject.import + subject.log_messages.last.should be_log_message(:key => "completed") + end + + it "should create a ImportLogmessage :failed when failed" do + subject.loader.stub(:import).and_raise("import failed") + subject.import + subject.log_messages.last.should be_log_message(:key => "failed") + end + + end end -- cgit v1.2.3