Skip to content

Instantly share code, notes, and snippets.

@neudabei
neudabei / snippet.rb
Created Aug 10, 2018
fl_medium_blogpost
View snippet.rb
# These two queries
subject_categories = SubjectCategory.in_alphabetical_order
interested_subject_categories = current_user.interested_subject_categories
# will now return the objects set up in our test
let(:subject_category_interests) { [subject_category_one, subject_category_three] }
let(:subject_categories) { [subject_category_one, subject_category_two, subject_category_three] }
@neudabei
neudabei / snippet.rb
Last active Aug 14, 2018
fl_medium_blogpost
View snippet.rb
# ...
{ fields:
subject_categories.map do |sc|
selected = interested_subject_categories.include?(sc)
{ title: sc.title, value: sc.id.to_s, selected: selected }
end
}
View describe_subject_category_interest_props_using_doubles.rb
describe '#subject_category_interest_props' do
let(:current_user) { double(:user) }
let(:subject_category_one) { double(:subject_category_one, id: 1, title: 'subject-category-title-1') }
let(:subject_category_two) { double(:subject_category_two, id: 2, title: 'subject-category-title-2') }
let(:subject_category_three) { double(:subject_category_three, id: 3, title: 'subject-category-title-3') }
let(:subject_category_interests) { [subject_category_one, subject_category_three] }
let(:subject_categories) { [subject_category_one, subject_category_two, subject_category_three] }
View describe_subject_category_interest_props.rb
describe '#subject_category_interest_props' do
## arrange
# create all subject categories
let!(:subject_category_one) { FactoryBot.create(:subject_category, id: 1, title: 'subject-category-title-1') }
let!(:subject_category_two) { FactoryBot.create(:subject_category, id: 2, title: 'subject-category-title-2') }
let!(:subject_category_three) { FactoryBot.create(:subject_category, id: 3, title: 'subject-category-title-3') }
# a learner has some subject category interests