1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

updates tests to use fixtures

This commit is contained in:
Nicolas Florentin 2016-04-05 12:28:42 +02:00
parent 2c2e4dfb51
commit b6dcacaa8a
2 changed files with 7 additions and 8 deletions

View File

@ -1,14 +1,11 @@
class AvailabilitiesTest < ActionDispatch::IntegrationTest
setup do
@profile = Profile.create!(gender: true, birthday: 20.years.ago, first_name: "Admin", last_name: "Sleede", phone: "06542868451")
@admin = User.create!(cgu: true, username: 'blabla', email: 'abc@sleede.com', password: 'kikoulol', password_confirmation: 'kikoulol', profile: @profile)
@admin.add_role(:admin)
login_as(@admin, scope: :user)
admin = User.with_role(:admin).first
login_as(admin, scope: :user)
end
test "return availability by id" do
a = Availability.create!(start_at: Time.now, end_at: 2.hours.from_now, available_type: 'trainings')
a = Availability.take
get "/api/availabilities/#{a.id}"
assert_equal 200, response.status

View File

@ -2,13 +2,15 @@ require 'test_helper'
class AvailabilityTest < ActiveSupport::TestCase
test "length must be at least 1h" do
a = Availability.new(start_at: Time.now, end_at: 15.minutes.from_now)
a = Availability.first
a.end_at = a.start_at + 15.minutes
assert a.invalid?
assert a.errors.key?(:end_at)
end
test "if type available_type is 'machines' check that there is minimum 1 association" do
a = Availability.new(start_at: Time.now, end_at: 2.hours.from_now, available_type: 'machines')
a = Availability.where(available_type: 'machines').first
a.machines_availabilities.destroy_all
assert a.invalid?
assert a.errors.key?(:machine_ids)
end