Soc/test/models/micropost_test.rb

38 lines
840 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "test_helper"
class MicropostTest < ActiveSupport::TestCase
setup do
@micropost = microposts(:one)
assert @micropost.valid?
end
test "must have a user" do
@micropost.user = nil
assert_not @micropost.valid?
end
test "must have content" do
@micropost.content = nil
assert_not @micropost.valid?
end
2023-10-19 17:46:41 +00:00
test "can add tags" do
assert_empty @micropost.tags
assert_difference "@micropost.tags.count", +3 do
@micropost.set_tags("foo", "bar", "baz")
end
end
test "duplicate tags are not added" do
assert_empty @micropost.tags
assert_difference "@micropost.tags.count", +3 do
@micropost.set_tags("foo", "bar", "baz")
end
assert_no_difference "@micropost.tags.count" do
@micropost.set_tags("bar", "baz")
2023-10-19 17:46:41 +00:00
end
end
end