From 11d1d1bf97f08050ee16af109320158e42d58bb0 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 31 May 2013 00:27:38 -0400 Subject: [PATCH 1/5] Initial attempt at tests --- app/models/alert.rb | 2 +- test/fixtures/alerts.yml | 18 ++++++++++++++---- test/fixtures/users.yml | 14 +++++--------- test/unit/alert_test.rb | 31 ++++++++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/app/models/alert.rb b/app/models/alert.rb index 75d7b80..0d79e38 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -30,7 +30,7 @@ class Alert < ActiveRecord::Base } def alerted? - @alerted + self.alerted end def course_name diff --git a/test/fixtures/alerts.yml b/test/fixtures/alerts.yml index 1fcbefb..5eb6612 100644 --- a/test/fixtures/alerts.yml +++ b/test/fixtures/alerts.yml @@ -2,12 +2,22 @@ one: user_id: 1 - department: MyString - course: MyString + department: CSE + course: 101 alerted: false + semester: US13 two: user_id: 1 - department: MyString - course: MyString + department: IAH + course: 241A + alerted: true + semester: FS13 + +three: + user_id: 2 + department: TES + course: 312 alerted: false + semester: SS14 + diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index c63aac0..819ceaa 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,11 +1,7 @@ # 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 diff --git a/test/unit/alert_test.rb b/test/unit/alert_test.rb index b59c65e..e803214 100644 --- a/test/unit/alert_test.rb +++ b/test/unit/alert_test.rb @@ -1,7 +1,32 @@ require 'test_helper' class AlertTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @alert_one = alerts(:one) + @alert_two = alerts(:two) + @alert_three = alerts(:three) + + @user_one = users(:one) + end + + test "creating a new alert creates an 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 + # again, should test with actual user + #assert Alert.user_alerts(@user_one).all? { |a| a == @user_one } + #end end From 5a3b540ec26fe65792dc41310d9f9dbc3fccf1e9 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 31 May 2013 22:53:35 -0400 Subject: [PATCH 2/5] More test stuff --- test/unit/alert_test.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/unit/alert_test.rb b/test/unit/alert_test.rb index e803214..8a12865 100644 --- a/test/unit/alert_test.rb +++ b/test/unit/alert_test.rb @@ -9,7 +9,7 @@ class AlertTest < ActiveSupport::TestCase @user_one = users(:one) end - test "creating a new alert creates an alert" do + test "should create a new alert" do assert_kind_of Alert, Alert.new end @@ -25,8 +25,11 @@ class AlertTest < ActiveSupport::TestCase assert !Alert.user_alerts(@user_one).empty? end - #test "should only return alerts for correct user when asked" do - # again, should test with actual user - #assert Alert.user_alerts(@user_one).all? { |a| a == @user_one } - #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 From c28c038b9c5dde2837bb4f9ab8cf25ceb3798148 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 4 Jun 2013 01:21:25 -0400 Subject: [PATCH 3/5] Include Devise test helpers --- test/test_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bf1192..e24de7e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,3 +11,8 @@ class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... end + +class ActionController::TestCase + include Devise::TestHelpers +end + From 4831fd71e868976807c9114d6bcff67da872d7f1 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 27 Jun 2013 00:55:11 -0400 Subject: [PATCH 4/5] add fixtures to test or something --- test/functional/alerts_controller_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/functional/alerts_controller_test.rb b/test/functional/alerts_controller_test.rb index 5f146ca..8de454a 100644 --- a/test/functional/alerts_controller_test.rb +++ b/test/functional/alerts_controller_test.rb @@ -3,6 +3,8 @@ require 'test_helper' class AlertsControllerTest < ActionController::TestCase setup do @alert = alerts(:one) + @alert = alerts(:two) + @alert = alerts(:three) end test "should get index" do From b49fca81b528e6d1df1f6ea10f542a905ef3426e Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 19 Jul 2013 01:13:50 -0400 Subject: [PATCH 5/5] Fix tests in various ways --- test/fixtures/alerts.yml | 3 +++ test/functional/alerts_controller_test.rb | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/test/fixtures/alerts.yml b/test/fixtures/alerts.yml index 5eb6612..43f4205 100644 --- a/test/fixtures/alerts.yml +++ b/test/fixtures/alerts.yml @@ -6,6 +6,7 @@ one: course: 101 alerted: false semester: US13 + sections: [1, 2, 3] two: user_id: 1 @@ -13,6 +14,7 @@ two: course: 241A alerted: true semester: FS13 + sections: [3, 6, 9] three: user_id: 2 @@ -20,4 +22,5 @@ three: course: 312 alerted: false semester: SS14 + sections: [5, 6, 11] diff --git a/test/functional/alerts_controller_test.rb b/test/functional/alerts_controller_test.rb index 8de454a..c72c92f 100644 --- a/test/functional/alerts_controller_test.rb +++ b/test/functional/alerts_controller_test.rb @@ -3,8 +3,10 @@ require 'test_helper' class AlertsControllerTest < ActionController::TestCase setup do @alert = alerts(:one) - @alert = alerts(:two) - @alert = alerts(:three) + + @user = users(:one) + + sign_in :user, @user end test "should get index" do @@ -20,7 +22,12 @@ class AlertsControllerTest < ActionController::TestCase test "should create alert" 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 assert_redirected_to alert_path(assigns(:alert)) @@ -37,7 +44,12 @@ class AlertsControllerTest < ActionController::TestCase end 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)) end