Skip to content

Instantly share code, notes, and snippets.

View alanmaciel's full-sized avatar
Work and play, same thing, differing conditions. ~Mark Twain

Alan Maciel alanmaciel

Work and play, same thing, differing conditions. ~Mark Twain
View GitHub Profile
@alanmaciel
alanmaciel / capybara cheat sheet
Created February 15, 2022 01:52 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@alanmaciel
alanmaciel / request_logger.rb
Created April 1, 2020 19:50 — forked from jugyo/request_logger.rb
Rack middleware for logging all rails request
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
capitales_dict = {
"Aguascalientes" : "Aguascalientes",
"Baja California" : "Mexicali",
"Baja California Sur" : "La Paz",
"Campeche" : "Campeche",
"Chihuahua" : "Chihuahua",
"Chiapas" : "Tuxtla Gutiérrez",
"Coahuila" : "Saltillo",
"Colima" : "Colima",
"Durango" : "Victoria",
validates :title, :released_on, :duration, presence: true
validates :description, length: { minimum: 25 }
validates :total_gross, numericality: { greater_than_or_equal_to: 0 }
validates :image_file_name, allow_blank: true, format: {
with: /\w+\.(gif|jpg|png)\z/i,
message: "must reference a GIF, JPG, or PNG image"
}
require 'spec_helper'
describe "Viewing an individual movie" do
it "shows the movie's details" do
movie = Movie.create(movie_attributes)
visit movie_url(movie)
expect(page).to have_text(movie.title)
expect(page).to have_text(movie.rating)
require 'spec_helper'
describe "Navigating movies" do
it "allows navigation from the detail page to the listing page" do
movie = Movie.create(movie_attributes)
visit movie_url(movie)
require 'spec_helper'
describe "Viewing the list of movies" do
it "shows the movies" do
# Arrange
movie1 = Movie.create(title: "Iron Man",
rating: "PG-13",
total_gross: 318412101.00,
description: "Tony Stark builds an armored suit to fight the throes of evil",
require 'spec_helper'
describe "Viewing a list of reviews" do
it "shows the reviews for a specific movie" do
movie1 = Movie.create(movie_attributes(title: "Iron Man"))
review1 = movie1.reviews.create(review_attributes(name: "Roger Ebert"))
review2 = movie1.reviews.create(review_attributes(name: "Gene Siskel"))
movie2 = Movie.create(movie_attributes(title: "Superman"))
review3 = movie2.reviews.create(review_attributes(name: "Peter Travers"))
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
require 'spec_helper'
describe "Editing a movie" do
it "updates the movie and shows the movie's updated details" do
movie = Movie.create(movie_attributes)
visit movie_url(movie)
click_link 'Edit'