Skip to content

Commit

Permalink
Test importer
Browse files Browse the repository at this point in the history
  • Loading branch information
luilver committed Feb 20, 2021
1 parent c70273d commit 063ac09
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
19 changes: 19 additions & 0 deletions spec/factories/importer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryBot.define do
factory :importer do
entity_type { :lead }
entity_id { 1 }
attachment_file_size { Random::rand(1..1024) }
attachment_file_name { "#{FFaker::Filesystem::file_name}.#{%w[xls xlsx].sample}" }
attachment_content_type { %w[text/xml application/xml].sample }
status { FFaker::Lorem.word }
created_at { FactoryBot.generate(:time) }
updated_at { FactoryBot.generate(:time) }
end
end
39 changes: 35 additions & 4 deletions spec/models/files/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,44 @@
#
# Table name: importers
#
# id :integer not null, primary key
# filename :string(64) default(""), not null
# md5sum :string(32) default(""), not null
# id :integer not null, primary key
# entity_type :string
# entity_id :integer
# attachment_file_size :integer
# attachment_file_name :string(255)
# attachment_content_type :string(255)
# status :string(255)
# created_at :datetime
# updated_at :datetime
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

RSpec.describe Importer, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
it "should create a new instance given valid attributes" do
Importer.create!(attributes_for(:importer))
end

describe "validates" do
it "attachment" do
is_expected.to have_attached_file(:attachment)
end

it "attachment presence" do
is_expected.to validate_attachment_presence(:attachment)
end

xit "attachment file size" do
is_expected.to validate_attachment_size(:attachment).
less_than(10.megabytes)
end

it "attachment content type" do
is_expected.to validate_attachment_content_type(:attachment).
allowing('text/xml', 'application/xml',
'application/vnd.ms-excel', 'application/x-ole-storage',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet').
rejecting('text/plain')
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'rspec/rails'
require 'capybara/rails'
require 'paper_trail/frameworks/rspec'
require "paperclip/matchers"

require 'factory_bot_rails'
require 'ffaker'
Expand Down Expand Up @@ -47,6 +48,7 @@
config.include Warden::Test::Helpers
config.include DeviseHelpers
config.include FeatureHelpers
config.include Paperclip::Shoulda::Matchers

Warden.test_mode!

Expand Down

0 comments on commit 063ac09

Please sign in to comment.