Skip to content

Instantly share code, notes, and snippets.

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 / request_logger.rb
Created Apr 1, 2020 — forked from jugyo/request_logger.rb
Rack middleware for logging all rails request
View request_logger.rb
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
View gist:579055ad49ca4ca4963f80bd68a0c78b
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",
View xp_validations_model.rb
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"
}
View xp_show_object_spec.rb
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)
View xp_navigate_objects_spec.rb
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)
View xp_list_objects_spec.rb
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",
View xp_list_child_objects_spec.rb
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"))
View xp_helper_spec.rb
# 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 }
View xp_edit_object_spec.rb
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'
View xp_delete_object_spec.rb
require 'spec_helper'
describe "Deleting a movie" do
it "destroys the movie and shows the movie listing without the deleted movie" do
movie = Movie.create(movie_attributes)
visit movie_path(movie)
click_link 'Delete'