Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

Feyonce

cancan’s bitmask

  • bitmask

  • by the way, it appears that cancan has been abandoned. We ended up rolling out our authorization.

devise

  • You can override the default behaviour by creating an after_sign_in_path_for via

Switch to omniauth

  • we made a major overhaul by switching to omniauth rather than using the devise email & password.
    • As per the omniauth wiki I needed to rebuild many of the paths that devise had created for us via the registerable and Database Authenticatable modules and reconfigure the appropriate controllers as well.
    • To its credit, the Devise::TestHelpers, type: :controller held up through the transition, which was a big help.

Bundle clean is the jam

  • bundle clean --force
  • bundle update Saved my @ss.

Before block versus let in rspec

  • use let to define all of the dependent objects, and to use before do to setup needed configuration or any mocks/stubs needed by the examples. via the comments section

Transient Factory Girl Properties

I needed a way to pass in some parameters into my factory. Enter transient properties.

The Eventual Code
1
2
3
4
5
6
7
8
9
10
11
factory :track_with_lessons do
  ignore do
    lesson_count 3
    topic_count 2
  end

  after(:create) do |track, evaluator|
    evaluator.topic_count.times { track.add_topic(create(:topic_with_lessons, lesson_count: evaluator.lesson_count))}
    track.save!
  end
end

A gotcha: The getting started readme was outdated so I was trying to use transient do which was not working. It appears that this will be fixed in the next release…

Capybara within block

When searching for an element with a div like within('div#first.drawer') do it truly means within, not like this can be the same element you are looking for, it has to be nested inside this element.

Testing with JSON

Found this to be a good place to start but I couldn’t get his method to actually work.

What he did
1
2
3
4
5
6
7
it "updates empty summary field" do
  @incoming_params[:id] = @dvd.id
  @incoming_params[:summary] =  'some summary'
  post 'entry/update', @incoming_params.to_json
  @entry.reload
  expect(@entry.summary).to eq 'some summary'
end
This is what worked for me
1
2
3
4
5
6
7
8
9
10
describe 'POST #topic_order' do
  it 'saves a new topic order' do
    sign_in_teacher
    track = create(:track_with_lessons)
    original_order = track.topic_order
    post :topic_order, "data"=> {"topic_order"=>"#{track.topic_order.last},#{track.topic_order.first}", "track_id"=>"#{track.id}"}, format: :json
    track.reload
    expect(track.topic_order).to eq original_order.reverse
  end
end

Comments