Sha256: 5dd4676e7e198cf07aa8a473c7ea4e25a4f71bc8f92c6544ae473cc54d844968
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
# encoding: utf-8 RSpec.describe ActiveRecordJsonImporter::Importer do context "with valid ActiveRecord class" do before(:all) do @table_name = "pools" @file_name = "input.json" @invalid_file_name = "invalid_input.json" create_test_table_and_activerecord(@table_name) @active_record_class = @table_name.singularize.camelize.constantize create_valid_json_file(@file_name) create_invalid_json_file(@invalid_file_name) end after(:all) do drop_test_table(@table_name) delete_json_file(@file_name) delete_json_file(@invalid_file_name) end context "with valid input" do it "imports the file" do importer = ActiveRecordJsonImporter::Importer.new(file: @file_name, active_record_class: @active_record_class) expect(importer.import).to be_truthy expect(@active_record_class.count).to eq(2) end end context "with invalid input" do it "raises an Exception" do importer = ActiveRecordJsonImporter::Importer.new(file: @invalid_file_name, active_record_class: @active_record_class) expect{importer.import}.to raise_exception(JSON::ParserError) end end end context "with invalid ActiveRecord class" do it "raises an Exception" do expect{importer = ActiveRecordJsonImporter::Importer.new(file: @invalid_file_name, active_record_class: "any object")}.to raise_exception(RuntimeError, "invalid active_record_class. any object") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_record_json_importer-0.0.1 | spec/lib/active_record_json_importer_spec.rb |