I was browsing shoulda matchers and context in order to refactor some text and make them more coincise and readable, but thorough, the documentation I could not find how to test this in specific:
(I'm following Hartl tutorial, and I'm trying to refactor in the Minitest way, not Rspec)
default_scope -> { order(created_at: :desc) }
has_one_attached :image
&
validates :image, content_type: { in: %w[image/jpeg image/gif image/png],
message: 'must be a valid image format' },
size: { less_than: 5.megabytes,
strong textmessage: 'should be less than 5MB' }
this:
attr_accessor :remember_token, :activation_token, :reset_token
before_save :downcase_email
before_create :create_activation_digest
this:
resources :account_activations, only: [:edit]
resources :password_resets, only: %i[new create edit update]
resources :microposts, only: %i[create destroy]
resources :relationships, only: %i[create destroy]
In general here are the ways you can test the pieces you've posted:
have_one_attached
matcher you can use to test has_one_attached
.user_test
— for instance, should validate_presence_of(:email)
, should validate_length_of(:email).is_at_most(255)
, etc.route
. I will say about this that you will probably get better mileage per test in writing an integration or system test which exercises the functionality that is accessible via the route rather than test the route directly. But at least that matcher is there should you want that level of granularity.Hope that helps — let me know if you need more help.