source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/factories/admin_users.rb
Ruby
mit
4,370
main
609
FactoryBot.define do factory :admin_user do sequence(:name) { |n| "admin#{n}" } sequence(:email) { |n| "admin#{n}@odin.com" } password { 'password123' } status { :activated } role { :core } trait :with_otp do otp_secret { AdminUser.generate_otp_secret } otp_required_for_login { tr...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/factories/users.rb
Ruby
mit
4,370
main
224
FactoryBot.define do factory :user do sequence(:username) { |n| "foobar#{n}" } sequence(:email) { |n| "foo#{n}@bar.com" } password { 'foobar' } avatar { 'http://github.com/fake-avatar' } path end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/factories/paths.rb
Ruby
mit
4,370
main
242
FactoryBot.define do factory :path do sequence(:title) { |n| "test path#{n}" } sequence(:position) { |n| n } description { 'A Path' } identifier_uuid { SecureRandom.uuid } badge_uri { 'badge-foundations.svg' } end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/builders/tailwind_form_builder_spec.rb
Ruby
mit
4,370
main
5,046
require 'rails_helper' # To update all snapshots run: `UPDATE_SNAPSHOTS=true rspec spec/builders/tailwind_form_builder_spec.rb` class TestHelper < ActionView::Base include InlineSvg::ActionView::Helpers end RSpec.describe TailwindFormBuilder do subject(:builder) { described_class.new(:user, form_object, TestHelp...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/seeds/test_users_and_admins_spec.rb
Ruby
mit
4,370
main
1,374
require 'rails_helper' RSpec.describe 'Generating test users and admins' do context 'when development environment' do before do allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development')) end it 'creates test users' do load './db/seeds/test_users_and_admins.rb'...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/tasks/project_submissions_spec.rb
Ruby
mit
4,370
main
1,043
require 'rails_helper' require 'rake' describe ':project_submissions' do before do Rake.application.rake_require 'tasks/project_submissions' Rake::Task.define_task(:environment) end let(:project_submissions_discard) do Rake::Task['project_submissions:discard'].reenable Rake.application.invoke_t...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/tasks/lesson_previews_spec.rb
Ruby
mit
4,370
main
682
require 'rails_helper' require 'rake' describe ':project_submissions' do before do Rake.application.rake_require 'tasks/lesson_previews' Rake::Task.define_task(:environment) end describe 'lesson_previews:destroy_expired' do let(:run_task) do Rake::Task['lesson_previews:destroy_expired'].reenab...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/tasks/curriculum_spec.rb
Ruby
mit
4,370
main
750
require 'rails_helper' require 'rake' describe ':curriculum' do before do allow($stdout).to receive(:write) Rake.application.rake_require 'tasks/curriculum' Rake::Task.define_task(:environment) end describe 'curriculum:update_content' do let!(:lesson) do create( :lesson, gi...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/adaptors/feature_spec.rb
Ruby
mit
4,370
main
677
require 'rails_helper' RSpec.describe Feature do describe '.enabled?' do context 'when the feature is enabled' do it 'returns true' do actor = instance_double(User) allow(Flipper).to receive(:enabled?).with(:test_feature, actor).and_return(true) expect(described_class.enabled?(:tes...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/devise.rb
Ruby
mit
4,370
main
270
RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::IntegrationHelpers, type: :system config.include Devise::Test::IntegrationHelpers, type: :request config.include Warden::Test::Helpers end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/vcr.rb
Ruby
mit
4,370
main
504
VCR.configure do |vcr_config| vcr_config.cassette_library_dir = 'spec/vcr' vcr_config.filter_sensitive_data('<GITHUB_API_TOKEN>') do ENV['GITHUB_API_TOKEN'] end vcr_config.filter_sensitive_data('<GITHUB_APP_ID>') { ENV['GITHUB_APP_ID'] } vcr_config.filter_sensitive_data('<GITHUB_SECRET>') { ENV['GITHUB_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/retry.rb
Ruby
mit
4,370
main
253
require 'rspec/retry' if ENV['CI'].present? RSpec.configure do |config| config.verbose_retry = true config.display_try_failure_messages = true config.around :each, type: :system do |ex| ex.run_with_retry retry: 2 end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/capybara.rb
Ruby
mit
4,370
main
1,104
Capybara.default_max_wait_time = 5 Capybara.default_normalize_ws = true Capybara.save_path = File.expand_path(ENV.fetch('CAPYBARA_ARTIFACTS', './tmp/capybara')) Capybara.disable_animation = true Capybara.configure do |config| config.test_id = 'data-test' config.automatic_label_click = true config.server_port = 3...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/oauth.rb
Ruby
mit
4,370
main
325
OmniAuth.config.test_mode = true def mock_oauth_provider(provider) OmniAuth.config.mock_auth[provider.to_sym] = OmniAuth::AuthHash.new( provider: provider.to_s, uid: '123', info: { email: 'odinstudent@example.com', name: 'chrissy shenko', image: 'http://github.com/fake-avatar' } )...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/cuprite.rb
Ruby
mit
4,370
main
659
require 'capybara/cuprite' module CupriteHelpers def pause page.driver.pause end def debug(*) page.driver.debug(*) end end Capybara.register_driver(:odin_cuprite) do |app| Capybara::Cuprite::Driver.new( app, window_size: [1200, 1200], browser_options: {}, flatten: false, process...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/precompile_assets.rb
Ruby
mit
4,370
main
845
RSpec.configure do |config| config.before(:suite) do examples = RSpec.world.filtered_examples.values.flatten has_no_system_tests = examples.none? { |example| example.metadata[:type] == :system } if ENV['CI'] $stdout.puts "\n🚀️️ CI detected. Skip assets compilation.\n" next end if h...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/view_components.rb
Ruby
mit
4,370
main
377
require 'view_component/test_helpers' require 'capybara/rspec' RSpec.configure do |config| config.include ViewComponent::TestHelpers, type: :component config.include Capybara::RSpecMatchers, type: :component config.include Devise::Test::ControllerHelpers, type: :component config.before(:each, type: :component...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/pages/project_submissions/form.rb
Ruby
mit
4,370
main
1,110
module Pages module ProjectSubmissions class Form extend Dry::Initializer include Capybara::DSL option :repo_url, default: -> { 'https://github.com/myname/my-project' } option :live_preview_url, default: -> { 'https://myprojectlivepreview.com' } option :previewable, default: -> { tr...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/shared_examples/shared_examples_for_likeable.rb
Ruby
mit
4,370
main
2,151
require 'rails_helper' RSpec.shared_examples 'likeable' do |factory| let(:record) { create(factory) } it { is_expected.to have_many(:likes).dependent(:destroy) } it { is_expected.to respond_to(:likes_count) } describe '#liked_by?' do context 'when the record is liked by the user' do it 'returns tru...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/support/shared_examples/shared_examples_for_authenticatable_with_two_factor.rb
Ruby
mit
4,370
main
2,003
require 'rails_helper' RSpec.shared_examples 'authenticatable_with_two_factor' do |factory| let(:record) { create(factory, :pending) } describe '#generate_two_factor_secret_if_missing!' do context 'when the otp secret is not present' do it 'generates a new otp secret' do record.otp_secret = nil ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/helpers/lessons_helper_spec.rb
Ruby
mit
4,370
main
1,643
require 'rails_helper' RSpec.describe LessonsHelper do describe '#github_edit_url' do let(:lesson) { create(:lesson) } it 'returns the github edit url for the lesson' do expect(helper.github_edit_url(lesson)).to eql( 'https://github.com/TheOdinProject/curriculum/edit/main/lesson_course/lesson_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/helpers/application_helper_spec.rb
Ruby
mit
4,370
main
3,288
require 'rails_helper' RSpec.describe ApplicationHelper do describe 'title' do it 'sets the title' do helper.title('Courses') expect(helper.content_for(:title)).to eql('Courses | The Odin Project') end context 'when there is no input' do it 'returns nil' do expect(title).to be_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/helpers/announcement_helper_spec.rb
Ruby
mit
4,370
main
442
require 'rails_helper' RSpec.describe AnnouncementHelper do describe '#disabled_announcement_ids' do let(:cookies) do { 'announcement_10' => 'disabled', 'announcement_20' => 'disabled', 'not_a_announcement_15' => 'disabled', 'announcement_' => 'disabled' } end ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/helpers/qr_code_helper_spec.rb
Ruby
mit
4,370
main
287
require 'rails_helper' RSpec.describe QrCodeHelper do describe '#qr_code_as_svg' do it 'returns an svg representation of a qr code' do expect(helper.qr_code_as_svg('https://www.theodinproject.com')) .to match_snapshot('qr_code_helper/qr_code_svg') end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/helpers/button_helper_spec.rb
Ruby
mit
4,370
main
1,154
require 'rails_helper' RSpec.describe ButtonHelper do before do allow(helper).to receive(:resource_name).and_return('user') end describe '#sign_up_button' do it 'returns a sign up button' do expect(helper.sign_up_button).to eq('<a class="button button--primary" href="/sign_up">Sign up</a>') en...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/lesson_preview_spec.rb
Ruby
mit
4,370
main
437
require 'rails_helper' RSpec.describe LessonPreview do it { is_expected.to validate_presence_of(:content) } it { is_expected.to validate_length_of(:content).is_at_most(70_000) } describe '.expired' do it 'returns 2 expired lesson previews' do expired = create_list(:lesson_preview, 2, created_at: 1.mon...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/announcement_spec.rb
Ruby
mit
4,370
main
4,213
require 'rails_helper' RSpec.describe Announcement do it { is_expected.to belong_to(:created_by) } it { is_expected.to validate_presence_of(:message) } it { is_expected.to validate_length_of(:message).is_at_most(100) } it { is_expected.to validate_presence_of(:expires_at) } it { is_expected.to allow_value('...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/user_provider_spec.rb
Ruby
mit
4,370
main
602
require 'rails_helper' RSpec.describe UserProvider do it { is_expected.to belong_to(:user) } describe '.find_user' do let(:auth) { {} } let(:user_provider_finder) { instance_double(OmniauthProviders::Finder) } let(:user_provider) { instance_double(described_class, user:) } let(:user) { instance_do...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/path_spec.rb
Ruby
mit
4,370
main
1,492
require 'rails_helper' RSpec.describe Path do subject(:path) { described_class.new } it { is_expected.to have_many(:users) } it { is_expected.to have_many(:courses).order(:position) } it { is_expected.to have_many(:lessons).through(:courses) } it { is_expected.to have_many(:path_prerequisites).dependent(:de...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/interview_concept_spec.rb
Ruby
mit
4,370
main
321
require 'rails_helper' RSpec.describe InterviewConcept do subject(:interview_concept) { create(:interview_concept) } it { (is_expected.to have_many(:interview_survey_concepts)) } it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_length_of(:name).is_at_least(2).is_at_most(25) } end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/interview_survey_concept_spec.rb
Ruby
mit
4,370
main
256
require 'rails_helper' RSpec.describe InterviewSurveyConcept do subject(:interview_survey_concept) { create(:interview_survey_concept) } it { (is_expected.to belong_to(:interview_survey)) } it { (is_expected.to belong_to(:interview_concept)) } end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flag_spec.rb
Ruby
mit
4,370
main
3,709
require 'rails_helper' RSpec.describe Flag do subject(:flag) { described_class.new } it { is_expected.to belong_to(:flagger) } it { is_expected.to belong_to(:project_submission) } it { is_expected.to belong_to(:resolved_by).optional } it { is_expected.to validate_presence_of(:reason) } it { is_expected.t...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/point_spec.rb
Ruby
mit
4,370
main
1,120
require 'rails_helper' RSpec.describe Point do subject { described_class.new(discord_id: '123') } it { is_expected.to validate_presence_of(:discord_id) } it { is_expected.to validate_uniqueness_of(:discord_id).case_insensitive } describe '#increment_points_by' do let(:user_points) { described_class.creat...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/path_prerequisite_spec.rb
Ruby
mit
4,370
main
300
require 'rails_helper' RSpec.describe PathPrerequisite do subject { create(:path_prerequisite) } it { is_expected.to belong_to(:path) } it { is_expected.to belong_to(:prerequisite).class_name('Path') } it { is_expected.to validate_uniqueness_of(:prerequisite_id).scoped_to(:path_id) } end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/user_spec.rb
Ruby
mit
4,370
main
7,677
require 'rails_helper' RSpec.describe User do subject(:user) { create(:user) } it { is_expected.to validate_uniqueness_of(:email).ignoring_case_sensitivity } it { is_expected.to allow_value('example@email.com').for(:email) } it { is_expected.not_to allow_value('bademail').for(:email) } it { is_expected.to v...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/interview_survey_spec.rb
Ruby
mit
4,370
main
508
require 'rails_helper' RSpec.describe InterviewSurvey do subject(:interview_survey) { create(:interview_survey) } it { is_expected.to belong_to(:user) } it { is_expected.to have_many(:interview_survey_concepts) } it { is_expected.to validate_presence_of(:interview_date) } it { is_expected.to allow_value(T...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/lesson_spec.rb
Ruby
mit
4,370
main
5,925
require 'rails_helper' RSpec.describe Lesson do subject(:lesson) { create(:lesson) } it { is_expected.to belong_to(:section) } it { is_expected.to have_one(:course).through(:section) } it { is_expected.to have_one(:content) } it { is_expected.to have_many(:project_submissions) } it { is_expected.to have_m...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/section_spec.rb
Ruby
mit
4,370
main
250
require 'rails_helper' RSpec.describe Section do subject { described_class.new } it { is_expected.to belong_to(:course) } it { is_expected.to have_many(:lessons).order(:position) } it { is_expected.to validate_presence_of(:position) } end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/course_spec.rb
Ruby
mit
4,370
main
1,601
require 'rails_helper' RSpec.describe Course do subject(:course) { described_class.new } it { is_expected.to belong_to(:path) } it { is_expected.to have_many(:sections).order(:position) } it { is_expected.to have_many(:lessons).through(:sections) } it { is_expected.to validate_presence_of(:position) } d...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/lesson_completion_spec.rb
Ruby
mit
4,370
main
881
require 'rails_helper' RSpec.describe LessonCompletion do subject { described_class.new } it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:lesson) } it { is_expected.to belong_to(:course).optional } it { is_expected.to belong_to(:path).optional } it { is_expected.to validate_uniquene...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/project_submission_spec.rb
Ruby
mit
4,370
main
7,777
require 'rails_helper' RSpec.describe ProjectSubmission do subject(:project_submission) { create(:project_submission) } it_behaves_like 'likeable', :project_submission it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:lesson) } it { is_expected.to have_many(:flags) } it { is_expected...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/admin_user_spec.rb
Ruby
mit
4,370
main
7,473
require 'rails_helper' RSpec.describe AdminUser do subject(:admin_user) { create(:admin_user) } it_behaves_like 'authenticatable_with_two_factor', :admin_user it_behaves_like 'two_factor_authenticatable' it { is_expected.to have_many(:flags).dependent(:restrict_with_exception).with_foreign_key(:resolved_by_i...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/like_spec.rb
Ruby
mit
4,370
main
872
require 'rails_helper' RSpec.describe Like do subject { create(:like) } it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:likeable).counter_cache(true) } it { is_expected.to validate_presence_of(:likeable_type) } it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(%i[likeable...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/users/theme_spec.rb
Ruby
mit
4,370
main
1,375
require 'rails_helper' RSpec.describe Users::Theme do describe '.default_themes' do it 'returns the default themes' do expect(described_class.default_themes).to contain_exactly( an_object_having_attributes(name: 'light', icon: 'moon'), an_object_having_attributes(name: 'dark', icon: 'sun') ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/notifications/flag_notification_spec.rb
Ruby
mit
4,370
main
1,433
require 'rails_helper' RSpec.describe Notifications::FlagNotification do subject(:flag_notification) { described_class } let(:flag) { create(:flag) } let(:recipient) { create(:user) } let(:title) { 'Test title' } let(:url) { '/test_path' } let(:message) { 'test message' } describe 'database delivery' d...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/reports/user_sign_ups_day_stat_spec.rb
Ruby
mit
4,370
main
2,610
require 'rails_helper' RSpec.describe Reports::UserSignUpsDayStat do describe '.for_date_range' do it 'returns all user sign up stats for the given date range' do create(:user, created_at: Time.utc(2022, 1, 1)) create(:user, created_at: Time.utc(2022, 1, 2)) create(:user, created_at: Time.utc(2...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/reports/path_lesson_completions_day_stat_spec.rb
Ruby
mit
4,370
main
5,290
require 'rails_helper' RSpec.describe Reports::PathLessonCompletionsDayStat do it { is_expected.to belong_to(:path) } it { is_expected.to belong_to(:course) } describe '.for_date_range' do it 'returns path lesson completion stats for the given date range' do course = create(:course) create(:less...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/reports/all_lesson_completions_day_stat_spec.rb
Ruby
mit
4,370
main
2,864
require 'rails_helper' RSpec.describe Reports::AllLessonCompletionsDayStat do describe '.for_date_range' do it 'returns all lesson completion stats for the given date range' do create(:lesson_completion, created_at: Time.utc(2022, 1, 1)) create(:lesson_completion, created_at: Time.utc(2022, 1, 2)) ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/reports/period_spec.rb
Ruby
mit
4,370
main
783
require 'rails_helper' RSpec.describe Reports::Period do describe '.all' do it 'returns all valid periods' do periods = described_class.all expect(periods.map(&:name)).to eq(%w[day month year]) end end describe '.find' do context 'when period with the same name is found' do it 're...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/github/push_event_spec.rb
Ruby
mit
4,370
main
837
require 'rails_helper' RSpec.describe Github::PushEvent do subject(:push_event) { described_class.new(payload) } let(:payload) do { ref:, head_commit: { modified: ['url/one', 'url/two'], } } end let(:ref) { 'refs/heads/main' } describe '#merged_to_main?' do context 'wh...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/github/lesson_content_importer_spec.rb
Ruby
mit
4,370
main
2,879
require 'rails_helper' RSpec.describe Github::LessonContentImporter do subject(:importer) { described_class.new(lesson) } let(:lesson) do create( :lesson, title: 'Ruby Basics', github_path: '/ruby_basics/variables', content: create(:content, body: lesson_content) ) end let(:le...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/omniauth_providers/builder_spec.rb
Ruby
mit
4,370
main
417
require 'rails_helper' module OmniauthProviders RSpec.describe Builder do describe '#build' do subject(:builder) { described_class.new(auth, user) } let(:auth) { OmniAuth::AuthHash.new(provider: 'github', uid: '123') } let(:user) { create(:user) } it 'creates a new user provider' do ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/omniauth_providers/finder_spec.rb
Ruby
mit
4,370
main
1,466
require 'rails_helper' module OmniauthProviders RSpec.describe Finder do subject(:finder) { described_class.new(auth) } let(:auth) do OmniAuth::AuthHash.new( provider: 'github', uid: '123', info: { email: 'john@odin.com', name: 'John', image: 'http...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/action_spec.rb
Ruby
mit
4,370
main
409
require 'rails_helper' RSpec.describe Flags::Action do describe '.all' do it 'returns all available flag actions' do expect(described_class.all.map(&:value)).to eq( I18n.t('flag_actions').pluck(:value) ) end end describe '.for' do it 'returns the flag action for the given value' ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/action_factory_spec.rb
Ruby
mit
4,370
main
906
require 'rails_helper' RSpec.describe Flags::ActionFactory do describe '#action' do subject { described_class.for(action) } context "when action is 'dismiss'" do let(:action) { :dismiss } it { is_expected.to eq(Flags::Actions::Dismiss) } end context "when action is 'ban'" do let(...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/actions/notify_user_spec.rb
Ruby
mit
4,370
main
1,786
require 'rails_helper' RSpec.describe Flags::Actions::NotifyUser do let(:admin_user) { create(:admin_user) } let(:flag) { create(:flag) } describe '#perform' do context 'when successful' do it 'discards the project submission in 7 days' do expect { described_class.perform(admin_user:, flag:) }...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/actions/dismiss_spec.rb
Ruby
mit
4,370
main
1,035
require 'rails_helper' RSpec.describe Flags::Actions::Dismiss do let(:admin_user) { create(:admin_user) } let(:flag) { create(:flag) } describe '#perform' do context 'when successful' do it 'changes the flag action taken to dismissed' do expect { described_class.perform(admin_user:, flag:) } ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/actions/remove_project_submission_spec.rb
Ruby
mit
4,370
main
1,308
require 'rails_helper' RSpec.describe Flags::Actions::RemoveProjectSubmission do let(:admin_user) { create(:admin_user) } let(:flag) { create(:flag) } describe '#perform' do context 'when successful' do it 'removes the project submission' do expect { described_class.perform(admin_user:, flag:)...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/actions/null_action_spec.rb
Ruby
mit
4,370
main
390
require 'rails_helper' RSpec.describe Flags::Actions::NullAction do let(:admin_user) { create(:admin_user) } let(:flag) { create(:flag) } describe '#perform' do it 'returns an unsuccessful result' do result = described_class.perform(admin_user:, flag:) expect(result).not_to be_success exp...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/models/flags/actions/ban_spec.rb
Ruby
mit
4,370
main
1,374
require 'rails_helper' RSpec.describe Flags::Actions::Ban do let(:admin_user) { create(:admin_user) } let(:flag) { create(:flag) } describe '#perform' do context 'when successful' do it 'bans the learner' do project_submission_owner = instance_double(User, ban!: true) allow(flag).to re...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/next_lesson_spec.rb
Ruby
mit
4,370
main
1,428
require 'rails_helper' RSpec.describe NextLesson do subject(:next_lesson) { described_class.new(course, lesson_completions) } let(:course) { create(:course) } let!(:lesson_one) { create(:lesson, course:) } let!(:lesson_two) { create(:lesson, course:) } let!(:lesson_three) { create(:lesson, course:) } des...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/course_progress_spec.rb
Ruby
mit
4,370
main
1,477
require 'rails_helper' class LessonCompletions def initialize(completed_lessons) @completed_lessons = completed_lessons end def where(lesson_id:) @completed_lessons.find_all { |lesson| lesson_id.include?(lesson) } end end RSpec.describe CourseProgress do subject(:course_progress) { described_class....
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/discord_notifier_spec.rb
Ruby
mit
4,370
main
488
require 'rails_helper' RSpec.describe DiscordNotifier do let(:notification) do instance_double(Notifications::DailySummary, message: 'A MESSAGE', destination: 'https://A-DESTINATION') end describe '#notify' do it 'sends the notification to discord' do VCR.use_cassette('discord_notification', recor...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/markdown_converter_spec.rb
Ruby
mit
4,370
main
6,451
require 'rails_helper' require './lib/kramdown/document_sections' RSpec.describe MarkdownConverter do describe '#as_html' do it 'converts the markdown to html with sections' do markdown = <<~MARKDOWN ### First section header some content ### Second section header some conte...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/messages/dead_link_spec.rb
Ruby
mit
4,370
main
1,218
require 'rails_helper' RSpec.describe Messages::DeadLink do subject(:message) { described_class.new(flag) } let(:flag) do create( :flag, created_at: Time.zone.local(2021, 8, 1), project_submission: create(:project_submission, lesson:, user:), reason: :inappropriate, extra: 'I fin...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/users/reset_progress_spec.rb
Ruby
mit
4,370
main
1,108
require 'rails_helper' RSpec.describe Users::ResetProgress do subject(:service) { described_class.call(user) } let!(:user) { create(:user, path: foundations_path) } let!(:foundations_path) { create(:path, default_path: true) } before do create(:lesson_completion, lesson: create(:lesson), user:) creat...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/notifications/daily_summary_spec.rb
Ruby
mit
4,370
main
850
require 'rails_helper' RSpec.describe Notifications::DailySummary do subject(:notification) { described_class.new } describe '#message' do before do travel_to Time.utc(2020, 4, 10) end it 'returns the daily summary message' do expect(notification.message).to eql( "**TOP Summary Fo...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/notifications/flag_submission_spec.rb
Ruby
mit
4,370
main
1,298
require 'rails_helper' RSpec.describe Notifications::FlagSubmission do subject(:notification) { described_class.new(flag) } let(:flag) do create( :flag, id: 120, flagger:, project_submission: flagged_submission, reason: :inappropriate, extra: 'I find it offensive' ) e...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
spec/services/courses/mark_completed_lessons_spec.rb
Ruby
mit
4,370
main
867
require 'rails_helper' RSpec.describe Courses::MarkCompletedLessons do describe '#call' do context 'when the lesson is included in users lesson completions' do it 'marks the lesson as completed' do user = create(:user) lesson = create(:lesson) create(:lesson_completion, lesson:, use...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/seeds/path_builder.rb
Ruby
mit
4,370
main
1,163
require './lib/seeds/helpers' require './lib/seeds/course_builder' module Seeds class PathBuilder include Helpers attr_accessor :identifier_uuid, :title, :description, :position, :default_path, :short_title, :badge_uri def initialize @seeded_courses = [] yield(self) @path = path ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/seeds/helpers.rb
Ruby
mit
4,370
main
314
module Seeds module Helpers def destroy_removed_seeds(persisted_collection, seeded_collection) removed_uuids = persisted_collection.map(&:identifier_uuid) - seeded_collection.map(&:identifier_uuid) persisted_collection.where(identifier_uuid: removed_uuids).find_each(&:destroy) end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/seeds/course_builder.rb
Ruby
mit
4,370
main
1,475
require './lib/seeds/helpers' require './lib/seeds/section_builder' module Seeds class CourseBuilder include Seeds::Helpers attr_accessor :identifier_uuid, :title, :description, :position, :show_on_homepage, :badge_uri def initialize(path, position) @path = path @position = position @...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/seeds/lesson_builder.rb
Ruby
mit
4,370
main
1,303
module Seeds class LessonBuilder def initialize(section, position, attributes) @section = section @position = position @attributes = attributes end def self.build(section, position, attributes) new(section, position, attributes).lesson end # rubocop: disable Metrics/AbcSi...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/seeds/section_builder.rb
Ruby
mit
4,370
main
1,186
# rubocop: disable Style/ClassVars require './lib/seeds/lesson_builder' module Seeds class SectionBuilder @@total_seeded_lessons = Hash.new(0) attr_accessor :identifier_uuid, :title, :description, :position attr_reader :seeded_lessons def initialize(course, position) @course = course @p...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/tasks/spec.rake
Ruby
mit
4,370
main
353
# frozen_string_literal: true if Rails.env.local? require 'rspec/core/rake_task' namespace :spec do # Usage: `bin/rails spec:fast` desc 'Run all specs except system specs' RSpec::Core::RakeTask.new(:fast) do |t| t.exclude_pattern = 'spec/system/**/*' t.rspec_opts = '--order rand' t.v...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/tasks/heroku.rake
Ruby
mit
4,370
main
444
namespace :heroku do desc 'Heroku release task - runs on every code push, runs before postdeploy task' task release: :environment do Rake::Task['db:prepare'].invoke Rake::Task['db:migrate'].invoke Rake::Task['db:seed'].invoke Rake::Task['curriculum:content:import'].invoke end desc 'Heroku postd...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/tasks/curriculum.rake
Ruby
mit
4,370
main
983
namespace :curriculum do desc 'Grab Latest Lesson Content from Github' task update_content: :environment do Rake::Task['curriculum:content:import'].invoke Rake::Task['curriculum:content:verify'].invoke end namespace :content do desc 'Import all lessons content from GitHub' task import: :environ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/tasks/data_migrations/example.rake
Ruby
mit
4,370
main
645
# create new data migration rake task file and copy the contents of this file into it # # namespace :data_migrations do # # desc "<What will this task do?>" # task example_data_migration_name: :environment do # puts "Processing #{Lesson.count} lessons" # # progressbar = ProgressBar.create(total: Lesson.coun...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/generators/rails/seed_uuids/seed_uuids_generator.rb
Ruby
mit
4,370
main
321
require 'rails/generators' class Rails::SeedUuidsGenerator < Rails::Generators::Base def generate_uuids seed_files = Dir.glob('db/fixtures/**/*').reject { |f| File.directory?(f) } seed_files.each do |file_name| gsub_file file_name, 'create_uuid' do SecureRandom.uuid end end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/kramdown/document_sections.rb
Ruby
mit
4,370
main
1,337
require './lib/kramdown/converter/html_sections' require './lib/kramdown/content_section' class Kramdown::DocumentSections < Kramdown::Document START_OF_CONTENT = 0 END_OF_CONTENT = -1 def initialize(source, options = {}) @source = source super end def all_sections return [] if sections.none? ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/kramdown/content_section.rb
Ruby
mit
4,370
main
813
module Kramdown class ContentSection HEADER_LINE = 1 HEADER_AND_NEWLINE = 2 attr_reader :title, :header_location def initialize(title:, header_location: nil, content: nil) @title = title @header_location = header_location @content = content end def content "<section ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/kramdown/converter/html_sections.rb
Ruby
mit
4,370
main
580
require './lib/kramdown/content_section' class Kramdown::Converter::HtmlSections < Kramdown::Converter::Html H3_HEADER = 3 TOP_LEVEL_ELEMENT = 0 def convert(element, _indent = -@indent) @content_sections = [] super @content_sections end def convert_header(element, indent) if element.options...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
lib/kramdown/converter/odin_html.rb
Ruby
mit
4,370
main
1,384
# All Kramdown methods that can be overridden are listed here: https://kramdown.gettalong.org/rdoc/Kramdown/Converter/Html.html require 'kramdown/converter/html' module Kramdown module Converter module OdinHtml HEADER_LEVELS_TO_CONVERT = [3, 4].freeze EXTERNAL_LINK_ATTRIBUTES = { rel: 'noreferrer' }....
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/validators/url_validator.rb
Ruby
mit
4,370
main
426
class UrlValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) message = options[:message] || 'Must be a valid URL' record.errors.add(attribute, message) unless url_valid?(value) end # rubocop:disable Style/RescueModifier def url_valid?(url) url = URI.parse(url) rescue ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/markdown_converter.rb
Ruby
mit
4,370
main
599
require './lib/kramdown/document_sections' require './lib/kramdown/converter/odin_html' class MarkdownConverter def initialize(markdown) @markdown = markdown end def as_html sections = Kramdown::DocumentSections.new(markdown).all_sections if sections.any? sections.map { |section| parse_with_g...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/course_progress.rb
Ruby
mit
4,370
main
633
class CourseProgress def initialize(course, user) @course = course @user = user end def started? completed_lessons.positive? end def completed? pending_lessons.zero? end def percentage (completed_lessons * 100.0 / total_lessons).to_i end private attr_reader :course, :user ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/discord_notifier.rb
Ruby
mit
4,370
main
396
class DiscordNotifier def initialize(notification) @notification = notification end def self.notify(notification) new(notification).notify end def notify client.execute do |builder| builder.content = notification.message end end private attr_reader :notification def client ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/next_lesson.rb
Ruby
mit
4,370
main
655
class NextLesson def initialize(course, lesson_completions) @course = course @lesson_completions = lesson_completions end def to_complete next_uncompleted_lesson || remaining_lessons_to_complete.first end private attr_reader :course, :lesson_completions def next_uncompleted_lesson rema...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/messages/dead_link.rb
Ruby
mit
4,370
main
871
module Messages class DeadLink include Rails.application.routes.url_helpers attr_reader :flag def initialize(flag) @flag = flag end def title "One of your submissions has been flagged on #{flagged_date}" end def content "Hey #{username}, your project #{lesson_name} ha...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/project_submissions/mark_liked.rb
Ruby
mit
4,370
main
591
module ProjectSubmissions class MarkLiked def initialize(user:, project_submissions:) @user = user @project_submissions = project_submissions end def self.call(**) new(**).call end def call project_submissions.each do |submission| next if liked_submission_ids.excl...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/courses/mark_completed_lessons.rb
Ruby
mit
4,370
main
545
module Courses class MarkCompletedLessons def initialize(user:, lessons:) @user = user @lessons = lessons end def self.call(user:, lessons:) new(user:, lessons:).call end def call lessons.each do |lesson| next if completed_lesson_ids.exclude?(lesson.id) l...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/notifications/daily_summary.rb
Ruby
mit
4,370
main
877
module Notifications class DailySummary def message "**TOP Summary For #{Date.yesterday.to_fs(:long_ordinal)} (UTC)**\n" \ "#{user_sign_up_count} users signed up\n" \ "#{lesson_completion_count} lessons completed\n" \ "#{project_submission_count} project submissions added\n" \ ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/notifications/flag_submission.rb
Ruby
mit
4,370
main
604
module Notifications class FlagSubmission include Rails.application.routes.url_helpers delegate :flagger, :project_submission, :reason, :extra, to: :flag, private: true def initialize(flag) @flag = flag end def message "#{flagger.username} has flagged a submission on #{project_submi...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/services/users/reset_progress.rb
Ruby
mit
4,370
main
721
module Users class ResetProgress def initialize(user) @user = user @success = false end def self.call(user) new(user).call end def call user.transaction do delete_lesson_completions delete_project_submissions reset_default_path unless user.path.def...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/sort_component.rb
Ruby
mit
4,370
main
530
class SortComponent < ApplicationComponent def initialize(options:, selected: {}) @options = options @selected = selected end def selected_option options.find { |option| selected?(option) } || default_option end def default_option options.find { |option| option[:default] } end private ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/new_tab_text_link_component.rb
Ruby
mit
4,370
main
305
class NewTabTextLinkComponent < ApplicationComponent def initialize(text:, href:, classes:, data: nil, noreferrer: true) @text = text @href = href @classes = classes @data = data @noreferrer = noreferrer end private attr_reader :text, :href, :classes, :data, :noreferrer end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/logo_component.rb
Ruby
mit
4,370
main
441
class LogoComponent < ApplicationComponent renders_one(:small_icon, lambda do |classes:| image_tag 'icons/odin-icon.svg', alt: 'Odin Logo', class: "block lg:hidden #{classes}" end) def initialize(classes:, path: nil) @classes = classes @path = path end attr_reader :classes def before_render ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/content_container_component.rb
Ruby
mit
4,370
main
253
class ContentContainerComponent < ApplicationComponent renders_one :footer def initialize(classes: '', data_attributes: {}) @classes = classes @data_attributes = data_attributes end private attr_reader :classes, :data_attributes end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/pagination_component.rb
Ruby
mit
4,370
main
239
class PaginationComponent < ApplicationComponent def initialize(pagy:, resource_name:) @pagy = pagy @resource_name = resource_name end def render? pagy.pages > 1 end private attr_reader :pagy, :resource_name end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/card_component.rb
Ruby
mit
4,370
main
299
class CardComponent < ApplicationComponent renders_one :header, Card::HeaderComponent renders_one :body, Card::BodyComponent renders_one :footer, Card::FooterComponent def initialize(classes: '', id: '') @classes = classes @id = id end private attr_reader :classes, :id end