Skip to content

Instantly share code, notes, and snippets.

View sevenseacat's full-sized avatar
🏠
Working remotely

Rebecca Le sevenseacat

🏠
Working remotely
View GitHub Profile
class ProjectsController < ApplicationController
def create
@project = Project.new(project_params)
# authorization checking - this depends on the library you're using
# this example is for cancan
authorize! :create, @project
if @project.save
redirect_to projects_path, notice: 'Yay!'
module ApplicationHelper
require 'asciidoctor'
def asciidoctor(text)
Asciidoctor.convert(text)
end
require 'coderay'
def coderay(text)
#I tried data-lang="( ... etc) since the browser output does that.
app_development=# select * from spree_promotions;
-[ RECORD 1 ]+---------------------------
id | 1
description |
expires_at | 2014-09-24 16:00:00
starts_at | 2014-09-16 16:00:00
name | stepfresh's cool promotion
type |
usage_limit | 1
match_policy | all
(byebug) Net::SFTP
NameError Exception: uninitialized constant Net::SFTP
nil
(byebug) require 'net-sftp'
LoadError Exception: cannot load such file -- net-sftp
nil
(byebug) require 'net/sftp'
true
(byebug) Net::SFTP
Net::SFTP
Changes for the Second Edition
A lot has changed in the Rails testing world over the past five years, even if
the general principles stayed more or less the same. This book has been
substantially rewritten from its first edition, with almost no part of the book
unchanged. Here’s a more complete list of changes. (Not all of these changes
will be in the early beta versions.)
• All tools have been upgraded to their latest versions: Rails 4.1.x, Minitest
5.3.x, RSpec 3, and so on.
• The opening tutorial was completely re-written. It’s an all new example
which provides, I hope, a more gentle introduction to testing in Rails.
SELECT "spree_products".*
FROM "spree_products"
INNER JOIN "spree_variants" ON "spree_variants"."product_id" = "spree_products"."id"
AND "spree_variants"."is_master" = 't'
AND "spree_variants"."deleted_at" IS NULL
INNER JOIN "spree_prices" ON "spree_prices"."variant_id" = "spree_variants"."id"
AND "spree_prices"."deleted_at" IS NULL
WHERE "spree_products"."deleted_at" IS NULL
AND ("spree_products".deleted_at IS NULL or "spree_products".deleted_at >= '2014-09-01 07:57:37.112639')
AND ("spree_products".available_on <= '2014-09-01 07:57:37.113857')
$ rails c
Loading development environment (Rails 3.2.19)
irb(main):001:0> "test".parameterize
=> "test"
irb(main):004:0> helper.image_tag("ipads/150ipadmini.png", alt: "iPad Mini", :data => {:toggle => "collapse", :parent => "#ipadpanel", :target => "#ipadmini"})
=> "<img alt=\"iPad Mini\" data-parent=\"#ipadpanel\" data-target=\"#ipadmini\" data-toggle=\"collapse\" src=\"/images/ipads/150ipadmini.png\" />"
# I went and made a file in app/assets/images/ipads/150ipadmini.png
irb(main):005:0> helper.image_tag("ipads/150ipadmini.png", alt: "iPad Mini", :data => {:toggle => "collapse", :parent => "#ipadpanel", :target => "#ipadmini"})
=> "<img alt=\"iPad Mini\" data-parent=\"#ipadpanel\" data-target=\"#ipadmini\" data-toggle=\"collapse\" src=\"/assets/ipads/150ipadmini.png\" />"
$ rails g model Foo
invoke active_record
create db/migrate/20140819015801_create_foos.rb
create app/models/foo.rb
invoke test_unit
create test/models/foo_test.rb
create test/fixtures/foos.yml
filters = {}
filters[:name] = params[:name] if params[:name]
filters[:age] = params[:age] if params[:age]
filters[:gender] = params[:gender] if params[:gender]
# or some computation or other process for each field here instead, to mimic functionality that a simple slice wouldnt replicate
Person.where(filters)