Last active
November 16, 2021 01:10
-
-
Save Random-Stack-Random-Day/c059a7e820765e3c2a41276e9acac4e1 to your computer and use it in GitHub Desktop.
Playground
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" | |
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 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 | |
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 'faker' | |
FactoryBot.define do | |
factory :article do | |
trait :short_title do | |
title { Faker::Lorem.characters(number: 2) } | |
end | |
trait :short_desc do | |
description { Faker::Lorem.characters(number: 4) } | |
end | |
title { Faker::Lorem.characters(number: 8) } | |
description { Faker::Lorem.characters(number: 53) } | |
# trait :short_title do | |
# title { Faker::Lorem.sentence(word_count: 1) } | |
# end | |
# trait :long_title do | |
# title { Faker::Lorem.sentence(word_count: 15) } | |
# end | |
# trait :short_desc do | |
# description { Faker::Lorem.sentence(word_count: 3) } | |
# end | |
# trait :desc do | |
# description { Faker::Lorem.sentence(word_count: 12) } | |
# end | |
# trait :long_desc do | |
# description { Faker::Lorem.characters(word_count: 401) } | |
# end | |
end | |
# factory :good_article do | |
# trait :title do | |
# title { Faker::Lorem.sentence(word_count: 5) } | |
# end | |
# trait :desc do | |
# description { Faker::Lorem.sentence(word_count: 12) } | |
# end | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment