From 7c0ae629a2ea0079c8b5efbd4c41b6ca661eae91 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 7 Jun 2012 13:39:35 +0200 Subject: Add support for Exports. Refs #41 --- spec/controllers/exports_controller_spec.rb | 22 ++++++++++ spec/factories.rb | 9 +++++ spec/helpers/exports_helper_spec.rb | 15 +++++++ spec/models/export_log_message_spec.rb | 16 ++++++++ spec/models/export_spec.rb | 63 +++++++++++++++++++++++++++++ spec/views/exports/index.html.erb_spec.rb | 5 +++ spec/views/exports/new.html.erb_spec.rb | 5 +++ 7 files changed, 135 insertions(+) create mode 100644 spec/controllers/exports_controller_spec.rb create mode 100644 spec/helpers/exports_helper_spec.rb create mode 100644 spec/models/export_log_message_spec.rb create mode 100644 spec/models/export_spec.rb create mode 100644 spec/views/exports/index.html.erb_spec.rb create mode 100644 spec/views/exports/new.html.erb_spec.rb (limited to 'spec') diff --git a/spec/controllers/exports_controller_spec.rb b/spec/controllers/exports_controller_spec.rb new file mode 100644 index 000000000..e7a49a8e8 --- /dev/null +++ b/spec/controllers/exports_controller_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe ImportsController do + login_user + + describe "GET 'new'" do + it "returns http success" do + pending + get 'new' + response.should be_success + end + end + + describe "GET 'index'" do + it "returns http success" do + pending + get 'index' + response.should be_success + end + end + +end diff --git a/spec/factories.rb b/spec/factories.rb index c36f1c71a..fdd23eded 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -23,4 +23,13 @@ FactoryGirl.define do f.sequence(:key) { "key_#{n}" } end + factory :export do |f| + f.association :referential + end + + factory :export_log_message do |f| + f.association :export + f.sequence(:key) { "key_#{n}" } + end + end diff --git a/spec/helpers/exports_helper_spec.rb b/spec/helpers/exports_helper_spec.rb new file mode 100644 index 000000000..33257b1d1 --- /dev/null +++ b/spec/helpers/exports_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the ExportsHelper. For example: +# +# describe ExportsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe ExportsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/export_log_message_spec.rb b/spec/models/export_log_message_spec.rb new file mode 100644 index 000000000..8aa3cde6e --- /dev/null +++ b/spec/models/export_log_message_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe ExportLogMessage do + + describe "#attributes" do + + subject { create :export_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/export_spec.rb b/spec/models/export_spec.rb new file mode 100644 index 000000000..bccaa4c42 --- /dev/null +++ b/spec/models/export_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe Export do + + subject { create :export } + + 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 "#export" do + + before(:each) do + subject.stub :exporter => mock(:export => true) + end + + it "should create a ExportLogmessage :started when started" do + subject.export + subject.log_messages.first.should be_log_message(:key => "started") + end + + it "should create a ExportLogmessage :completed when completed" do + subject.export + subject.log_messages.last.should be_log_message(:key => "completed") + end + + it "should create a ExportLogmessage :failed when failed" do + pending + # subject.loader.stub(:export).and_raise("export failed") + subject.export + subject.log_messages.last.should be_log_message(:key => "failed") + end + + end + + describe "#options" do + + it "should be empty by default" do + subject.options.should be_empty + end + + end + + describe ".types" do + + it "should return available Export implementations" do + pending + Export.types.should =~ %w{NeptuneExport} + end + + end + + describe ".new" do + + it "should use type attribute to create a subclass" do + Export.new(:type => "NeptuneExport").should be_an_instance_of(NeptuneExport) + end + + end + +end diff --git a/spec/views/exports/index.html.erb_spec.rb b/spec/views/exports/index.html.erb_spec.rb new file mode 100644 index 000000000..781b5787b --- /dev/null +++ b/spec/views/exports/index.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "exports/index.html.erb" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/exports/new.html.erb_spec.rb b/spec/views/exports/new.html.erb_spec.rb new file mode 100644 index 000000000..d4a3b255a --- /dev/null +++ b/spec/views/exports/new.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "exports/new.html.erb" do + pending "add some examples to (or delete) #{__FILE__}" +end -- cgit v1.2.3