$ rails g model User
belongs_to
has_one
| =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') |
| OK, Let's begin. Hello, Everybody. | |
| My name is Narihiro Nakamura. | |
| Today, I'm talking about "Parallel worlds of CRuby's GC". | |
| I'm very happy now, because I'm meeting attendee in rubyconf. | |
| And, one of my dreams is to talk in rubyconf. | |
| So, I'm very happy and exciting. | |
| Today is my first presentation in English. | |
| My English is not good. |
| -- show running queries (pre 9.2) | |
| SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
| FROM pg_stat_activity | |
| WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
| ORDER BY query_start desc; | |
| -- show running queries (9.2) | |
| SELECT pid, age(clock_timestamp(), query_start), usename, query | |
| FROM pg_stat_activity | |
| WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
| before_filter: allow_cors_requests | |
| def allow_cors | |
| headers["Access-Control-Allow-Origin"] = "*" | |
| headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",") | |
| headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",") | |
| head(:ok) if request.request_method == "OPTIONS" | |
| # or, render text: '' | |
| # if that's more your style | |
| end |
| require 'rails_helper' | |
| RSpec.describe TodosController, :type => :controller do | |
| describe "GET #index" do | |
| #describe "POST #create" do | |
| #describe "GET #show" do | |
| #describe "PATCH #update" do (or PUT #update) | |
| #describe "DELETE #destroy" do | |
| #describe "GET #new" do |
| VCR.configure do |c| | |
| c.cassette_library_dir = 'spec/fixtures/vcr_cassettes' | |
| c.hook_into :webmock | |
| c.ignore_localhost = true | |
| c.default_cassette_options = { record: :new_episodes } | |
| c.allow_http_connections_when_no_cassette = false | |
| c.configure_rspec_metadata! | |
| c.ignore_hosts 'codeclimate.com' |
| class Pageviews < ActiveRecord::Base | |
| #google analytics api shenanigans | |
| require 'google/api_client' | |
| require 'date' | |
| include ReportingHelper | |
| def self.getviews post | |
| client, analytics, parameters = ReportingHelper.initclient | |
| parameters = { |
Fast/efficient approach:
-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
-> 1.3197s
Slow/naïve approach:
| -- show running queries (pre 9.2) | |
| SELECT procpid, age(query_start, clock_timestamp()), usename, current_query | |
| FROM pg_stat_activity | |
| WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
| ORDER BY query_start desc; | |
| -- show running queries (9.2) | |
| SELECT pid, age(query_start, clock_timestamp()), usename, query | |
| FROM pg_stat_activity | |
| WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |