This file contains 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
<body> | |
<div class="outer-block" style=""> | |
<div class="inner-block text-center"> | |
<blockquote class="font-weight-bold font-italic text-style"> | |
<div class="row"> | |
<div class="col-md-12 quote"> | |
The quote will appear here. | |
</div> | |
<div class="col-md-12 text-center author font-italic text-muted text-style"> |
This file contains 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
RSpec.describe UsersController, type: :controller do | |
# let can be used as instance variables, instead of @user | |
let(:create_user) { FactoryGirl.create(:user) } | |
let(:new_path){ new_user_path } | |
let(:edit_path){ edit_user_path } | |
# let can be used as parameters that can be shared across examples | |
let(:create_params){ | |
{ | |
name: "NAME", | |
age: "20" |
This file contains 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
# override as_json method of User class | |
def as_json(options={}) | |
h = { | |
name: self.name, | |
picture: self.picture.url(:medium), | |
age: self.age | |
} | |
h | |
end | |
# put helper methods, such as creating full name from given first_name and last_name attribute of user |
This file contains 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
# override as_json method of User class | |
def as_json(options={}) | |
super(only: [:picture, :age], | |
methods: [:name]) | |
end | |
# put helper methods, such as creating full name from given first_name and last_name attribute of user | |
def name | |
self.first_name +" " +self.last_name | |
end | |
# example response, note that timestamps, authentication token and password digest fields are not present |
This file contains 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
def as_json(options={}) | |
# options hash accepts four keys for better customization :only, :methods, :include, :except | |
# so whenever such keys are found, we call super with those keys to provide response consisting only those keys | |
if options.key?(:only) or options.key?(:methods) or options.key?(:include) or options.key?(:except) | |
h = super(options) | |
else | |
h = super(only: [:picture, :age], | |
methods: [:name], | |
include: {:emails => { :only => [:id, :email] }) | |
end |
This file contains 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
def index | |
@users = User.all | |
render json: @users | |
end |
This file contains 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
def index | |
@users = User.all.includes(:posts => [:comments]) | |
render json: @users | |
end |
This file contains 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 User < ApplicationRecord | |
has_many :posts | |
has_many :comments | |
end | |
class Post < ApplicationRecord | |
has_many :comments | |
belongs_to :user | |
end |
This file contains 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 SimpleCov | |
class SourceFile | |
class Line | |
def reinitialize_line(coverage) | |
raise ArgumentError, "Only Integer and nil accepted for coverage" unless coverage.is_a?(Integer) || coverage.nil? | |
@coverage = coverage | |
@skipped = false | |
end | |
end | |
end |
This file contains 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
Model.destroy_all | |
# if you haven't performed any other action after accidently deleting all records from Model, | |
# then _ would grab last response generated by Model.destroy_all | |
destroyed_records = _ | |
destroyed_records.each do |destroyed_record| | |
Model.create(destroyed_record.attributes) | |
end |
OlderNewer