require 'rails_helper'

describe SourceFile::<%= class_name %> do
  subject { create('source_file/<%= file_name %>', original_file: fixture_file("source_files/<%= file_name %>_1.csv") ) }
  <%- if options.source_record -%>
  let(:model) { SourceRecord::<%= class_name %> }
  <%- end -%>

  describe "#execute_loading_process" do
    it "loads" do
      subject.execute_loading_process
      subject.should_not have_log_entries /ERROR/
      subject.should have_log_entries 'Inladen gereed'

      model.count.should eq 99999
      record = model.first

      <%- attributes.each do |attr| -%>
        <%- if attr.type == 'date' -%>
      record.<%= attr.column_name %>.should eq "1981-03-09".to_date
        <%- elsif attr.numeric? -%>
      record.<%= attr.column_name %>.should eq 99999
        <%- else -%>
      record.<%= attr.column_name %>.should eq "99999"
        <%- end -%>
      <%- end -%>
    end
  end

  <%- if has_workflow? -%>
  describe '#after_activate_hook' do
    it 'calls the create or update hook of workflow instance (app/models/workflow_instance/data_setup)' do
      expect(WorkflowInstance).to receive(:create_or_update_from_<%= file_name %>)
      subject.execute_loading_process
    end
  end
  <%- end -%>
end
