I finally got this working but I am concerned I am being 'too' specific in my tests, and also that I am repeating myself a significant amount.
I could also combine all of the failures into a single test but that feels incorrect as I could change max to 500 and then the entire thing would fail.
Namely, I am not happy with the article = build sets everywhere, but is it correct?
articles.rb - Factory
require 'faker'
# Article Specs
# Title - Min 6, Max 100
# Desc - Min 10, Max 400
FactoryBot.define do
factory :article do
trait :short_title do
title { Faker::Lorem.characters(number: 5) }
end
trait :long_title do
title { Faker::Lorem.characters(number: 101) }
end
trait :short_desc do
description { Faker::Lorem.characters(number: 9) }
end
trait :long_desc do
description { Faker::Lorem.characters(number: 401) }
end
title { Faker::Lorem.characters(number: 8) }
description { Faker::Lorem.characters(number: 53) }
end
end
articles_controller_test.rb
require "test_helper"
require "faker"
class ArticlesControllerTest < ActionDispatch::IntegrationTest
setup do
@article = build(:article)
end
test "should get index" do
get articles_url
assert_response :success
end
test "should get new" do
get new_article_url
assert_response :success
end
test "should create article" do
assert_difference('Article.count') do
post articles_url, params: { article: { description: @article.description, title: @article.title }}
end
end
test "should deny due to small desc size" do
article = build(:article, :short_desc)
assert_no_difference('Article.count') do
post articles_url, params: { article: { description: article.description, title: article.title }}
end
end
test "should deny due to long desc size" do
article = build(:article, :long_desc)
assert_no_difference('Article.count') do
post articles_url, params: { article: { description: article.description, title: article.title }}
end
end
test "should deny due to small title size" do
article = build(:article, :short_title)
assert_no_difference('Article.count') do
post articles_url, params: { article: { description: article.description, title: article.title }}
end
end
test "should deny due to large title size" do
article = build(:article, :long_title)
assert_no_difference('Article.count') do
post articles_url, params: { article: { description: article.description, title: article.title }}
end
end
end
```