Code, Strings, and Keys

    • About Thomas Powell
    • Account
    • It’s been [0] days since [program] last updated
    • Login
    • Password Reset
    • Pianist / Accompanist / Music Director Resume
    • Reading List 2025
    • Register
    • Running Gear – Shoes, Treadmill, and Bandages
    • Site Map
Illustration of a bird flying.
  • rspec before(:all) is tempting but stubs don’t play nicely with it.

    I was looking at an rspec test with multiple expectations in the same example. before(:all) do SpecialClient.any_instance.stub(:login).and_return { true } end # # MUCH SPACE # # WOW # it “does stuff successfully” do # preceding code, including controller action expect(result.valid?).to be_true expect(response.body).to match /All is happy/ expect(response.code).to eq “200” end I wanted to add…

    May 1, 2014
  • Conditions on a has_many :through and ActiveRecord 4.1 enum

    Say you have a set of models (model names sanitized for generic posting) where the join table in the middle of a has_many :through has an enum that you want to add a filtered association for. class Student < ActiveRecord::Base has_many :student_grades has_many :grades, through: :student_grades end class StudentGrade < ActiveRecord::Base enum approval_status: [:not_reviewed, :rejected,…

    April 30, 2014
  • has_many :through, self referential models

    Hat tip to [has_many :through self-referential example] that sent me down the correct path on this. The challenge I had went a little deeper than the aforementioned post, however. I’m going to reuse the friend example, but with a twist. class Person < ActiveRecord::Base # id :integer end class Friendship < ActiveRecord::Base # source_friend_id :integer…

    April 29, 2014
←Previous Page
1 … 74 75 76 77 78 … 312
Next Page→

Code, Strings, and Keys

Proudly powered by WordPress