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
.... | |
gem 'carrierwave' | |
gem 'cloudinary' | |
.... |
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
group :development, :test do | |
gem 'rspec-rails' | |
end | |
group :test do | |
gem 'factory_bot_rails' | |
gem 'shoulda-matchers' | |
gem 'faker' | |
gem 'database_cleaner' | |
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 database cleaner at the top level | |
require 'database_cleaner' | |
Shoulda::Matchers.configure do |config| | |
config.integrate do |with| | |
with.test_framework :rspec | |
with.library :rails | |
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 'rails_helper' | |
RSpec.describe Article, type: :model do | |
# Validation tests | |
# ensure columns title and created_by are present before saving | |
it { should validate_presence_of(:title) } | |
it { should validate_presence_of(:content) } | |
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
class Article < ApplicationRecord | |
validates_presence_of :title, :content | |
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
FactoryBot.define do | |
factory :article do | |
title { Faker::Lorem.word } | |
content { Faker::Lorem.paragraph(2) } | |
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 'rails_helper' | |
RSpec.describe 'articles API', type: :request do | |
# initialize test data | |
let!(:articles) { create_list(:article, 10) } | |
let(:article_id) { articles.first.id } | |
# Test suite for GET /articles | |
describe 'GET /articles' do | |
# make HTTP get request before each example |
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
module RequestSpecHelper | |
# Parse JSON response to ruby hash | |
def json | |
JSON.parse(response.body) | |
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
# spec/rails_helper.rb | |
# [...] | |
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } | |
# [...] | |
RSpec.configuration do |config| | |
# [...] | |
config.include RequestSpecHelper, type: :request | |
# [...] | |
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
Rails.application.routes.draw do | |
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | |
resources :articles | |
end |
OlderNewer