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 | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
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
require 'rails_helper' | |
RSpec.describe TodosController, :type => :controller do | |
context "GET index" do | |
#context "POST create" do | |
#context "GET show" do | |
#context "PATCH update" do (or PUT update) | |
#context "DELETE destroy" do | |
#context "GET new" do |
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 | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
page.should render_template(:index) | |
#Redirecting | |
page.should redirect_to(movies_path) |
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
=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') |
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
1) backup production database: | |
heroku pgbackups:capture --expire --remote production | |
2) obtain url string to backup from step 1: | |
heroku pgbackups:url --app production_app_name --remote production_app_branch_name | |
3) transfer backup from production to staging app: | |
heroku pgbackups:restore DATABASE 'production_app_backup_url_string_from_step_2' --app production_app_name --app staging_app_branch_name |
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 CreateSearches < ActiveRecord::Migration | |
def self.up | |
ActiveRecord::Base.connection.execute <<-SQL | |
CREATE VIEW searches AS | |
SELECT authors.id AS searchable_id, authors.name AS term, | |
CAST ('Author' AS varchar) AS searchable_type | |
FROM authors | |
UNION | |
SELECT books.id AS searchable_id, books.title AS term, | |
CAST ('Book' AS varchar) AS searchable_type |
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 Search < ActiveRecord::Base | |
# We want to reference various models | |
belongs_to :searchable, :polymorphic => true | |
# Wish we could eliminate n + 1 query problems, | |
# but we can't include polymorphic models when | |
# using scopes to search in Rails 3 | |
# default_scope :include => :searchable | |
# Search.new('query') to search for 'query' |
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
require 'texticle/searchable' | |
class Book | |
# :title, String | |
# :author, String | |
extend Searchable(:title) | |
end | |
Book.create :title => "Poignant Guide to Ruby", :author => "_why" |
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 Address | |
# :street, String | |
# :city, String | |
# :state, String | |
# :country, String | |
scope :local, lambda { |query| search_by_street_or_city(query, query) } | |
scope :national, lambda {|query| search_by_state_or_country(query, query) } | |
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
# Based on | |
# https://github.com/ng/paperclip-watermarking-app/blob/master/lib/paperclip_processors/watermark.rb | |
# Modified by Laurynas Butkus | |
module Paperclip | |
class Watermark < Processor | |
# Handles watermarking of images that are uploaded. | |
attr_accessor :format, :whiny, :watermark_path, :position | |
def initialize file, options = {}, attachment = nil |
NewerOlder