aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorAlban Peignier2012-05-30 17:23:18 +0200
committerAlban Peignier2012-05-30 17:23:18 +0200
commit7082d66ec221aee194d64a17ab5d21eb2955f419 (patch)
tree19c381f9cf1d75adb499fc7dfd4b136614ab6ede /spec/models
parent0f9cec96c44a1102b0964123d26809cc1e2bab8f (diff)
downloadchouette-core-7082d66ec221aee194d64a17ab5d21eb2955f419.tar.bz2
Create and display ImportLogMessages. Refs #39
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/import_log_message_spec.rb16
-rw-r--r--spec/models/import_spec.rb32
2 files changed, 47 insertions, 1 deletions
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