-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added validations to micropost model
- Loading branch information
scarvill91
committed
Mar 29, 2015
1 parent
e18b91a
commit 9e2d70a
Showing
2 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Micropost < ActiveRecord::Base | ||
belongs_to :user | ||
validates :user_id, presence: true | ||
validates :content, presence: true, length: { maximum: 140 } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
require 'test_helper' | ||
|
||
class MicropostTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
|
||
def setup | ||
@user = users(:michael) | ||
# This code is not idiomatically correct. | ||
@micropost = Micropost.new(content: "Lorem ipsum", user_id: @user.id) | ||
end | ||
|
||
test "should be valid" do | ||
assert @micropost.valid? | ||
end | ||
|
||
test "user id should be present" do | ||
@micropost.user_id = nil | ||
assert_not @micropost.valid? | ||
end | ||
|
||
test "content should be present " do | ||
@micropost.content = " " | ||
assert_not @micropost.valid? | ||
end | ||
|
||
test "content should be at most 140 characters" do | ||
@micropost.content = "a" * 141 | ||
assert_not @micropost.valid? | ||
end | ||
end |