This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
{ fields: | |
subject_categories.map do |sc| | |
selected = interested_subject_categories.include?(sc) | |
{ title: sc.title, value: sc.id.to_s, selected: selected } | |
end | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def subject_category_interest_props | |
subject_categories = SubjectCategory.in_alphabetical_order | |
interested_subject_categories = current_user.interested_subject_categories | |
{ fields: | |
subject_categories.map do |sc| | |
selected = interested_subject_categories.include?(sc) | |
{ title: sc.title, value: sc.id.to_s, selected: selected } | |
end } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
puts Digest::SHA256.hexdigest("hello world!" + "2030350") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProofOfWork | |
require 'digest' | |
def initialize(difficulty:) | |
@required_number_of_zeros = difficulty | |
end | |
def find_nonce_for(block_content:) | |
nonce = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test_helper" | |
class UseVanityControllerTest < ActionController::TestCase | |
tests UseVanityController | |
def setup | |
super | |
metric :sugar_high | |
new_ab_test :pie_or_cake do | |
metrics :sugar_high |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UseVanityController < ActionController::Base | |
class TestModel | |
def test_method | |
Vanity.ab_test(:pie_or_cake) | |
end | |
end | |
attr_accessor :current_user | |
def index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require_relative 'sieve_of_eratosthenes' | |
class SieveTest < Minitest::Test | |
def test_a_few_primes | |
expected = [2, 3, 5, 7] | |
assert_equal expected, Sieve.new(10).primes | |
end | |
def test_primes |
NewerOlder