Created
November 4, 2013 11:00
-
-
Save mankind/7301038 to your computer and use it in GitHub Desktop.
happy path controller test generated by rails scaffold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails g scaffold course title:string start_day:date start_time:time cost:decimal approved:boolean picture:binary course_duration:integer | |
require 'test_helper' | |
class CoursesControllerTest < ActionController::TestCase | |
setup do | |
@course = courses(:one) | |
end | |
test "should get index" do | |
get :index | |
assert_response :success | |
assert_not_nil assigns(:courses) | |
end | |
test "should get new" do | |
get :new | |
assert_response :success | |
end | |
test "should create course" do | |
assert_difference('Course.count') do | |
post :create, course: { approved: @course.approved, cost: @course.cost, course_duration: @course.course_duration, picture: @course.picture, start_day: @course.start_day, start_time: @course.start_time, title: @course.title } | |
end | |
assert_redirected_to course_path(assigns(:course)) | |
end | |
test "should show course" do | |
get :show, id: @course | |
assert_response :success | |
end | |
test "should get edit" do | |
get :edit, id: @course | |
assert_response :success | |
end | |
test "should update course" do | |
patch :update, id: @course, course: { approved: @course.approved, cost: @course.cost, course_duration: @course.course_duration, picture: @course.picture, start_day: @course.start_day, start_time: @course.start_time, title: @course.title } | |
assert_redirected_to course_path(assigns(:course)) | |
end | |
test "should destroy course" do | |
assert_difference('Course.count', -1) do | |
delete :destroy, id: @course | |
end | |
assert_redirected_to courses_path | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class CourseTest < ActiveSupport::TestCase | |
# test "the truth" do | |
# assert true | |
# end | |
def setup | |
@course = Course.new | |
end | |
#this test passes | |
def test_valid | |
assert @course.valid? | |
end | |
#note that refute is the opposite of assert | |
#19 mins into http://www.youtube.com/watch?v=H1Czc3NL4c4 | |
def test_invalid_without_title | |
@coure.title = nil | |
refute @course.valid | |
end | |
def teardown | |
# Add code that need to be executed after each test | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment