Add some very basic testing on alerts.
This commit is contained in:
commit
e33c812a4b
|
@ -30,7 +30,7 @@ class Alert < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
|
|
||||||
def alerted?
|
def alerted?
|
||||||
@alerted
|
self.alerted
|
||||||
end
|
end
|
||||||
|
|
||||||
def course_name
|
def course_name
|
||||||
|
|
|
@ -2,12 +2,25 @@
|
||||||
|
|
||||||
one:
|
one:
|
||||||
user_id: 1
|
user_id: 1
|
||||||
department: MyString
|
department: CSE
|
||||||
course: MyString
|
course: 101
|
||||||
alerted: false
|
alerted: false
|
||||||
|
semester: US13
|
||||||
|
sections: [1, 2, 3]
|
||||||
|
|
||||||
two:
|
two:
|
||||||
user_id: 1
|
user_id: 1
|
||||||
department: MyString
|
department: IAH
|
||||||
course: MyString
|
course: 241A
|
||||||
|
alerted: true
|
||||||
|
semester: FS13
|
||||||
|
sections: [3, 6, 9]
|
||||||
|
|
||||||
|
three:
|
||||||
|
user_id: 2
|
||||||
|
department: TES
|
||||||
|
course: 312
|
||||||
alerted: false
|
alerted: false
|
||||||
|
semester: SS14
|
||||||
|
sections: [5, 6, 11]
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
||||||
|
one:
|
||||||
|
id: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
id: 2
|
||||||
|
|
||||||
# This model initially had no columns defined. If you add columns to the
|
|
||||||
# model remove the '{}' from the fixture names and add the columns immediately
|
|
||||||
# below each fixture, per the syntax in the comments below
|
|
||||||
#
|
|
||||||
one: {}
|
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ require 'test_helper'
|
||||||
class AlertsControllerTest < ActionController::TestCase
|
class AlertsControllerTest < ActionController::TestCase
|
||||||
setup do
|
setup do
|
||||||
@alert = alerts(:one)
|
@alert = alerts(:one)
|
||||||
|
|
||||||
|
@user = users(:one)
|
||||||
|
|
||||||
|
sign_in :user, @user
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
|
@ -18,7 +22,12 @@ class AlertsControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
test "should create alert" do
|
test "should create alert" do
|
||||||
assert_difference('Alert.count') do
|
assert_difference('Alert.count') do
|
||||||
post :create, alert: { alerted: @alert.alerted, course: @alert.course, department: @alert.department, user_id: @alert.user_id }
|
post :create, alert: {
|
||||||
|
course: @alert.course,
|
||||||
|
department: @alert.department,
|
||||||
|
semester: @alert.semester,
|
||||||
|
sections: @alert.sections
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to alert_path(assigns(:alert))
|
assert_redirected_to alert_path(assigns(:alert))
|
||||||
|
@ -35,7 +44,12 @@ class AlertsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update alert" do
|
test "should update alert" do
|
||||||
put :update, id: @alert, alert: { alerted: @alert.alerted, course: @alert.course, department: @alert.department, user_id: @alert.user_id }
|
put :update, id: @alert, alert: {
|
||||||
|
course: @alert.course,
|
||||||
|
department: @alert.department,
|
||||||
|
semester: @alert.semester,
|
||||||
|
sections: @alert.sections
|
||||||
|
}
|
||||||
assert_redirected_to alert_path(assigns(:alert))
|
assert_redirected_to alert_path(assigns(:alert))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,3 +11,8 @@ class ActiveSupport::TestCase
|
||||||
|
|
||||||
# Add more helper methods to be used by all tests here...
|
# Add more helper methods to be used by all tests here...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ActionController::TestCase
|
||||||
|
include Devise::TestHelpers
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,35 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class AlertTest < ActiveSupport::TestCase
|
class AlertTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
def setup
|
||||||
# assert true
|
@alert_one = alerts(:one)
|
||||||
# end
|
@alert_two = alerts(:two)
|
||||||
|
@alert_three = alerts(:three)
|
||||||
|
|
||||||
|
@user_one = users(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create a new alert" do
|
||||||
|
assert_kind_of Alert, Alert.new
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return false if has not been alerted" do
|
||||||
|
assert !@alert_one.alerted?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return true if has been alerted" do
|
||||||
|
assert @alert_two.alerted?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return alerts for user when asked" do
|
||||||
|
assert !Alert.user_alerts(@user_one).empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should only return alerts for correct user when asked" do
|
||||||
|
assert Alert.user_alerts(@user_one).all? { |a| a.user_id == @user_one.id }
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return the full course name" do
|
||||||
|
assert_equal @alert_one.course_name, "CSE 101"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue