import_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. require 'rails_helper'
  2. RSpec.describe Import, type: :model do
  3. let (:account) { Fabricate(:account) }
  4. let (:type) { 'following' }
  5. let (:data) { attachment_fixture('imports.txt') }
  6. describe 'validations' do
  7. it 'has a valid parameters' do
  8. import = Import.create(account: account, type: type, data: data)
  9. expect(import).to be_valid
  10. end
  11. it 'is invalid without an type' do
  12. import = Import.create(account: account, data: data)
  13. expect(import).to model_have_error_on_field(:type)
  14. end
  15. it 'is invalid without a data' do
  16. import = Import.create(account: account, type: type)
  17. expect(import).to model_have_error_on_field(:data)
  18. end
  19. it 'is invalid with too many rows in data' do
  20. import = Import.create(account: account, type: type, data: StringIO.new("foo@bar.com\n" * (ImportService::ROWS_PROCESSING_LIMIT + 10)))
  21. expect(import).to model_have_error_on_field(:data)
  22. end
  23. it 'is invalid when there are more rows when following limit' do
  24. import = Import.create(account: account, type: type, data: StringIO.new("foo@bar.com\n" * (FollowLimitValidator.limit_for_account(account) + 10)))
  25. expect(import).to model_have_error_on_field(:data)
  26. end
  27. end
  28. end