Sha256: 4c2b555c8407c40e239cff6d5c06f8d094858347b879fe47a4f81869ba9923b4

Contents?: true

Size: 1.82 KB

Versions: 10

Compression:

Stored size: 1.82 KB

Contents

require 'test_helper'

class AudioTest < ActiveSupport::TestCase

  setup do
    @valid = File.open("#{Rails.root}/test/fixtures/audios/audio.wav")
    @small = File.open("#{Rails.root}/test/fixtures/audios/small.wav")
    @large = File.open("#{Rails.root}/test/fixtures/audios/large.wav")
    @invalid = File.open("#{Rails.root}/test/fixtures/audios/invalid.wav")
    @undefined = File.open("#{Rails.root}/test/fixtures/audios/undefined.zip")
  end

  teardown do
    @valid.close
    @small.close
    @large.close
    @invalid.close
    @undefined.close
  end

  test "valid file assignment" do
    @audio = Audio.create(:file => @valid)
    assert @audio.valid?, "valid file assignment failed"
    assert @audio.file?, "should have a file"
  end

  test "inavlid file assignment" do
    @audio = Audio.create(:file => @invalid)
    assert !@audio.valid?, "invalid file assignment succeeded"
    assert @audio.errors[:file].include? "must be an audio file"
  end

  test "undefined file assignment" do
    @audio = Audio.create(:file => @undefined)
    assert !@audio.valid?, "undefined file assignment succeeded"
    assert @audio.errors[:file].include? "extension is invalid"
  end

  test "too large file assignment" do
    @audio = Audio.create(:file => @large)
    assert !@audio.valid?, "invalid file assignment succeeded"
    assert @audio.errors[:file].include? "size must be between 2 kilobytes and 2 megabytes"
  end

  test "too small file assignment" do
    @audio = Audio.create(:file => @small)
    assert !@audio.valid?, "invalid file assignment succeeded"
    assert @audio.errors[:file].include? "size must be between 2 kilobytes and 2 megabytes"
  end

  test "no file assignment" do
    @audio = Audio.create()
    assert !@audio.valid?, "invalid file assignment succeeded"
    assert @audio.errors[:file].include? "must be attached"
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
attached-1.0.4 test/dummy/test/models/audio_test.rb
attached-1.0.3 test/dummy/test/models/audio_test.rb
attached-1.0.2 test/dummy/test/models/audio_test.rb
attached-1.0.1 test/dummy/test/models/audio_test.rb
attached-1.0.0 test/dummy/test/unit/audio_test.rb
attached-0.6.0 test/dummy/test/unit/audio_test.rb
attached-0.5.9 test/dummy/test/unit/audio_test.rb
attached-0.5.8 test/dummy/test/unit/audio_test.rb
attached-0.5.7 test/dummy/test/unit/audio_test.rb
attached-0.5.6 test/dummy/test/unit/audio_test.rb