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 | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/clipboard_copy_spec.rb | Ruby | bsd-3-clause | 99 | main | 454 | require "rails_helper"
RSpec.describe ClipboardCopy, type: :view do
it "renders the clipboard copy button" do
render_component(text: "Hello")
expect(rendered).to have_css("button", text: "Copied!")
end
it "gracefully handles text containing ERB when processed by ERB" do
render_component(text: "<%= ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/color_schemes/css_spec.rb | Ruby | bsd-3-clause | 99 | main | 559 | require "rails_helper"
RSpec.describe ColorSchemes::Css do
describe "#call" do
it "renders valid css" do
validator = W3CValidators::CSSValidator.new
render_component(color_scheme: FactoryBot.build(:color_scheme))
validator_results = validator.validate_text(rendered)
expect(validator_re... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/code_block/code_spec.rb | Ruby | bsd-3-clause | 99 | main | 576 | require "rails_helper"
RSpec.describe CodeBlock::Code, type: :view do
it "renders contents of file" do
render CodeBlock::Code.new("def ruby = 'awesome'", language: "ruby")
expect(rendered).to have_content("def ruby = 'awesome'")
expect(rendered).to have_css("pre code span")
end
it "renders contents ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/code_block/app_file_spec.rb | Ruby | bsd-3-clause | 99 | main | 2,007 | require "rails_helper"
RSpec.describe CodeBlock::AppFile, type: :view do
before do
allow(view).to receive(:headers).and_return({"Content-Type" => "text/html"})
end
it "renders contents of file" do
render(CodeBlock::AppFile.new("spec/fixtures/code_block/app_file/example.rb"))
expect(rendered).to have... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/code_block/app_file_run_spec.rb | Ruby | bsd-3-clause | 99 | main | 543 | require "rails_helper"
RSpec.describe CodeBlock::AppFileRun, type: :view do
before do
allow(view).to receive(:headers).and_return({"Content-Type" => "text/html"})
end
it "renders contents of file" do
render_component("spec/fixtures/code_block/app_file/example.rb")
expect(rendered).to have_content(<... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/markdown/article_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,255 | require "rails_helper"
RSpec.describe Markdown::Article, type: :view do
before do
allow(view).to receive(:headers).and_return({"Content-Type" => "text/html"})
end
it "processes text" do
expect(render_component("Hello")).to match "Hello"
end
it "ignores unfenced erb at start of line" do
expect(r... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/markdown/base_spec.rb | Ruby | bsd-3-clause | 99 | main | 2,515 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe Markdown::Base, type: :view do
it "supports multiple headings" do
render_component <<~MD
# 1
## 2
### 3
#### 4
##### 5
###### 6
MD
expect(rendered.strip).to be ==
"<h1>1</h1> <h2>2</h2> <h3>3</... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/markdown/erb_spec.rb | Ruby | bsd-3-clause | 99 | main | 2,422 | require "rails_helper"
RSpec.describe "Markdown with Erb", type: :view do
subject do
Class.new(Markdown::Base) do
include Markdown::AllowsErb
def code_block(source, metadata = "", **attributes)
plain source
end
end
end
let(:template) { instance_double(ActionView::Template, typ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/markdown/toc_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,492 | require "rails_helper"
RSpec.describe Markdown::Toc, type: :view do
it "renders nothing for a markdown document without headers" do
render_component(<<~MD)
Hello
MD
expect(rendered).to eq("")
end
it "renders a table of contents from markdown with headers" do
render_component(<<~MD)
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/markdown/atom_spec.rb | Ruby | bsd-3-clause | 99 | main | 764 | require "rails_helper"
RSpec.describe Markdown::Atom, type: :view do
let(:template) { instance_double(ActionView::Template, type: "") }
it "processes text" do
expect(render_component("Hello")).to match "Hello"
end
it "ignores unfenced erb at start of line" do
expect(render_component("<%= 1 + 1 %>")).... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/pages/header_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,593 | require "rails_helper"
RSpec.describe Pages::Header, type: :view do
def render(**kwargs, &block)
described_class.new(**kwargs, &block).call(view_context: view)
end
describe "#call" do
it "renders the title" do
expect(render(title: "Hello")).to have_css(".page-header h1", text: "Hello")
end
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/views/components/atom/entry_content_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,815 | require "rails_helper"
RSpec.describe Atom::EntryContent do
let(:article) { FactoryBot.create(:page, request_path: "/articles/introducing-joy-of-rails") }
describe "#render" do
it "renders the article body as html without enhanced markdown" do
html = described_class.new(article).render
expect(html... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/lib/image_data_uri_spec.rb | Ruby | bsd-3-clause | 99 | main | 3,023 | require "spec_helper"
require_relative "../../lib/image_data_uri"
RSpec.describe ImageDataUri do
let(:png_data_uri) { "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==" }
let(:jpeg_data_uri) { "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBD... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/lib/html_fixtures/renderer_spec.rb | Ruby | bsd-3-clause | 99 | main | 409 | require "rails_helper"
RSpec.describe HtmlFixtures::Renderer do
it "renders all fixtures" do
HtmlFixtures::Renderer.new.render_all
expect(File.exist?(Rails.root.join("app", "javascript", "test", "fixtures", "views", "darkmode", "switch.html"))).to be true
expect(File.exist?(Rails.root.join("app", "javas... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/lib/tasks/embeddings_spec.rb | Ruby | bsd-3-clause | 99 | main | 282 | require "rails_helper"
RSpec.describe "rails deploy", type: :task do
describe ":finish" do
it "doesn’t blow up" do
FactoryBot.create(:page, :published)
expect {
Rake::Task["embeddings:upsert_random"].invoke
}.not_to raise_error
end
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/lib/tasks/deploy_spec.rb | Ruby | bsd-3-clause | 99 | main | 276 | require "rails_helper"
RSpec.describe "rails deploy", type: :task do
describe ":finish" do
it "doesn’t blow up" do
FactoryBot.create(:user, :primary_author)
expect {
Rake::Task["deploy:finish"].invoke
}.not_to raise_error
end
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/notifications.rb | Ruby | bsd-3-clause | 99 | main | 840 | # == Schema Information
#
# Table name: notifications
#
# id :integer not null, primary key
# processed_at :datetime
# read_at :datetime
# recipient_type :string not null
# seen_at :datetime
# type :string
# create... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/pages.rb | Ruby | bsd-3-clause | 99 | main | 816 | # == Schema Information
#
# Table name: pages
#
# id :string not null, primary key
# indexed_at :datetime
# published_at :datetime
# request_path :string not null
# revised_at :datetime
# upserted_at :datetime
# created_at :datetime not null
# updated_at :datetime ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/admin_users.rb | Ruby | bsd-3-clause | 99 | main | 498 | # == Schema Information
#
# Table name: admin_users
#
# id :integer not null, primary key
# email :string
# password_digest :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_admin_users_on_emai... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/newsletters.rb | Ruby | bsd-3-clause | 99 | main | 590 | # == Schema Information
#
# Table name: newsletters
#
# id :string not null, primary key
# content :text not null
# sent_at :datetime
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_n... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/users.rb | Ruby | bsd-3-clause | 99 | main | 1,102 | # == Schema Information
#
# Table name: users
#
# id :string not null, primary key
# confirmed_at :datetime
# email :string not null
# last_sign_in_at :datetime
# name :string
# password_digest :string
# created_at :datetime not null
# update... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/notification_events.rb | Ruby | bsd-3-clause | 99 | main | 403 | # == Schema Information
#
# Table name: notification_events
#
# id :integer not null, primary key
# notifications_count :integer default(0)
# params :json
# type :string
# created_at :datetime not null
# updated_at :datetime ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/polls.rb | Ruby | bsd-3-clause | 99 | main | 531 | # == Schema Information
#
# Table name: polls
#
# id :string not null, primary key
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
# author_id :string not null
#
# Indexes
#
# index_polls_on_author_id (author_id)... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/page_embeddings.rb | Ruby | bsd-3-clause | 99 | main | 252 | FactoryBot.define do
sequence(:random_embedding) do
Array.new(PageEmbedding::OPENAI_EMBEDDING_LENGTH) { rand(-0.1..0.1) }
end
factory :page_embedding do
id { SecureRandom.uuid_v7 }
embedding { generate(:random_embedding) }
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/color_schemes.rb | Ruby | bsd-3-clause | 99 | main | 1,463 | # == Schema Information
#
# Table name: color_schemes
#
# id :string not null, primary key
# name :string not null
# weight_100 :string not null
# weight_200 :string not null
# weight_300 :string not null
# weight_400 :string not null
# we... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/newsletter_subscriptions.rb | Ruby | bsd-3-clause | 99 | main | 527 | # == Schema Information
#
# Table name: newsletter_subscriptions
#
# id :string not null, primary key
# subscriber_type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# subscriber_id :string not null
#
# Indexe... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/topics.rb | Ruby | bsd-3-clause | 99 | main | 866 | # spec/factories/topics.rb
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# description :text
# name :string
# pages_count :integer default(0), not null
# slug :string not null
# status :string default("pending... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/application_events.rb | Ruby | bsd-3-clause | 99 | main | 513 | # == Schema Information
#
# Table name: application_events
#
# id :string not null, primary key
# data :text not null
# metadata :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# inde... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/snippets.rb | Ruby | bsd-3-clause | 99 | main | 747 | # == Schema Information
#
# Table name: snippets
#
# id :string not null, primary key
# author_type :string not null
# description :text
# filename :string
# language :string
# source :text not null
# title :string
# created_at :datetime not nul... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/polls/answers.rb | Ruby | bsd-3-clause | 99 | main | 674 | # == Schema Information
#
# Table name: polls_answers
#
# id :integer not null, primary key
# body :string not null
# position :integer default(0), not null
# votes_count :integer default(0), not null
# created_at :datetime not null
# updated_at :d... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/polls/votes.rb | Ruby | bsd-3-clause | 99 | main | 700 | # == Schema Information
#
# Table name: polls_votes
#
# id :integer not null, primary key
# device_uuid :string
# created_at :datetime not null
# updated_at :datetime not null
# answer_id :integer not null
# user_id :string
#
# Indexes
#
# index_polls_votes_on_a... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/polls/questions.rb | Ruby | bsd-3-clause | 99 | main | 599 | # == Schema Information
#
# Table name: polls_questions
#
# id :integer not null, primary key
# body :string not null
# position :integer default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# poll_id :string ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/examples/posts.rb | Ruby | bsd-3-clause | 99 | main | 545 | # == Schema Information
#
# Table name: examples_posts
#
# id :integer not null, primary key
# postable_type :string not null
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
# postable_id :integer ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/examples/posts/links.rb | Ruby | bsd-3-clause | 99 | main | 362 | # == Schema Information
#
# Table name: examples_posts_links
#
# id :integer not null, primary key
# url :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :examples_posts_link, class: "Examples::Posts::... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/examples/posts/markdowns.rb | Ruby | bsd-3-clause | 99 | main | 373 | # == Schema Information
#
# Table name: examples_posts_markdowns
#
# id :integer not null, primary key
# body :text not null
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :examples_posts_markdown, class: "Examples:... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/factories/examples/posts/images.rb | Ruby | bsd-3-clause | 99 | main | 365 | # == Schema Information
#
# Table name: examples_posts_images
#
# id :integer not null, primary key
# url :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :examples_posts_image, class: "Examples::Posts... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/generators/articles_generator_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,199 | require "rails_helper"
require_relative "../../lib/generators/article/article_generator"
RSpec.describe ArticleGenerator, type: :generator do
before do
FileUtils.rm_rf("app/assets/images/articles/my-new-article")
end
after do
FileUtils.rm_rf("app/assets/images/articles/my-new-article")
end
it "creat... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/controllers/analytics_spec.rb | Ruby | bsd-3-clause | 99 | main | 488 | require "rails_helper"
RSpec.describe "Analytics", type: :controller do
controller do
include Analytics
after_action do
plausible_event "Something Happened", props: {value: 42}
end
def index
render plain: "Hello, World!"
end
end
it "sends a plausible event" do
plausible_req... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/channels/connection_spec.rb | Ruby | bsd-3-clause | 99 | main | 554 | require "rails_helper"
RSpec.describe ApplicationCable::Connection, type: :channel do
it "successfully connects logged-in user" do
user = instance_double(User, id: "323")
connect "/cable", env: {"warden" => double(user: user)}
expect(connection.current_user).to eq user
end
it "successfully connects ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/channels/heartbeat_channel_spec.rb | Ruby | bsd-3-clause | 99 | main | 412 | require "rails_helper"
RSpec.describe HeartbeatChannel, type: :channel do
it "successfully subscribes user" do
stub_connection(current_user: FactoryBot.create(:user))
subscribe room_id: 42
expect(subscription).to be_confirmed
end
it "successfully subscribes guest" do
stub_connection(current_use... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/clients/application_client_spec.rb | Ruby | bsd-3-clause | 99 | main | 9,038 | require "rails_helper"
RSpec.describe ApplicationClient do
subject(:client) { described_class.new(token: "test") }
it "authorization header" do
stub_request(:get, "https://example.org/").with(headers: {"Authorization" => "Bearer test"})
assert_nothing_raised do
client.send(:get, "/")
end
end
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/clients/plausible_client_spec.rb | Ruby | bsd-3-clause | 99 | main | 601 | require "rails_helper"
RSpec.describe PlausibleClient, vcr: true do
subject(:client) { described_class.new }
describe "#post_event" do
it "posts an event to Plausible" do
response = client.post_event(
name: "test event",
url: "http://joyofrails.com/about",
headers: {
"U... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/jobs/pages/analyze_topics_job_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,591 | require "rails_helper"
RSpec.describe Pages::AnalyzeTopicsJob, type: :job do
describe "#perform" do
it "analyzes the topics of a page" do
page = FactoryBot.create(:page, request_path: "/articles/custom-color-schemes-with-ruby-on-rails")
response = {
id: "chatcmpl-ARm3zTYmf11ldAIJx9JywO8XjmKo... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/jobs/pages/embedding_job_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,520 | require "rails_helper"
RSpec.describe Pages::EmbeddingJob, type: :job do
it "updates page emebedding for given page" do
page = Page.find_or_create_by!(request_path: "/articles/custom-color-schemes-with-ruby-on-rails")
response = {
object: "list",
data: [
object: "embedding",
inde... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/jobs/pages/batch_upsert_pages_job_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,255 | require "rails_helper"
RSpec.describe Pages::BatchUpsertPagesJob, type: :job do
it "creates pages for sitepress resources" do
described_class.perform_now
expect(Page.count).to eq(SitepressPage.all.resources.size)
expect(Page.pluck(:request_path)).to include("/articles/custom-color-schemes-with-ruby-on-... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/jobs/pages/refresh_search_index_job_spec.rb | Ruby | bsd-3-clause | 99 | main | 943 | require "rails_helper"
RSpec.describe Pages::RefreshSearchIndexJob, type: :job do
describe Pages::RefreshSearchIndexJob::Batch do
it "doesn’t blow up when indexing the current pages" do
Page.upsert_collection_from_sitepress!
perform_enqueued_jobs
expect { Pages::RefreshSearchIndexJob::Batch.pe... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/jobs/emails/heartbeat_job_spec.rb | Ruby | bsd-3-clause | 99 | main | 504 | require "rails_helper"
RSpec.describe Emails::HeartbeatJob do
describe "#perform" do
it "sends a heartbeat email to admin users to exercise email provider integration" do
admin_user = FactoryBot.create(:admin_user)
Emails::HeartbeatJob.perform_later
perform_enqueued_jobs_and_subsequently_enqu... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/config/x_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,181 | require "rails_helper"
RSpec.describe "Custom configuration" do
describe "#application_name" do
it { expect(Rails.configuration.x.application_name).to eq("Joy of Rails") }
end
describe "#vapid" do
it { expect(Rails.configuration.x.vapid.subject).to eq("mailto:hello@example.com") }
it { expect(Rails.... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/config/litestream_spec.rb | Ruby | bsd-3-clause | 99 | main | 744 | require "rails_helper"
RSpec.describe "litestream.yml" do
# config/litestream/#{Rails.env}.yml is generated by config/initializers/litestream.rb
it "configures litestack replication" do
litestream_config = YAML.load_file(Rails.root.join("config", "litestream", "test.yml"))
litestream_config["dbs"].each do ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/notifiers/welcome_notifier_spec.rb | Ruby | bsd-3-clause | 99 | main | 510 | require "rails_helper"
RSpec.describe WelcomeNotifier do
describe ".deliver_to" do
it "sends at most once per user" do
allow(Emails::UserMailer).to receive(:welcome).and_return(double(deliver_later: nil))
user = FactoryBot.create(:user, :confirmed)
WelcomeNotifier.deliver_to(user)
perfo... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/requests.rb | Ruby | bsd-3-clause | 99 | main | 384 | module RequestSpecHelpers
def document
@document ||= Capybara.string(response.body)
end
end
RSpec.configure do |config|
config.include Warden::Test::Helpers, type: :request
config.include Rails.application.routes.url_helpers, type: :request
config.before(:each, type: :request) do
host! "example.com"... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/phlex_helpers.rb | Ruby | bsd-3-clause | 99 | main | 308 | module PhlexHelpers
def render_component(*, **, &)
render(described_class.new(*, **, &))
end
end
RSpec.configure do |config|
config.include PhlexHelpers, type: :view
config.before(:each, type: :view) do
allow(view).to receive(:headers).and_return({"Content-Type" => "text/html"})
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/mail_helpers.rb | Ruby | bsd-3-clause | 99 | main | 754 | module MailHelpers
def last_email
ActionMailer::Base.deliveries.last
end
def find_mail_to(email)
ActionMailer::Base.deliveries.find { |mail| mail.to.include?(email) }
end
def email_link(email, string)
raise ArgumentError, "Email is missing" if email.blank?
document = Capybara.string(email.h... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/webmock_vcr.rb | Ruby | bsd-3-clause | 99 | main | 979 | require "webmock/rspec"
require "vcr"
module WebmockHelpers
def json_response(body, **attrs)
{
status: 200,
body: body.to_json,
headers: {"Content-Type" => "application/json"}.merge(attrs.slice(:headers))
}.merge(attrs.except(:headers))
end
end
VCR.configure do |config|
config.cassette... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/system.rb | Ruby | bsd-3-clause | 99 | main | 1,257 | require "capybara/cuprite"
# Default to headless Chrome with Cuprite
#
# To run cuprite in Chrome browser
# HEADLESS=false bin/rspec
#
# To run with the inspector, use page.driver.debug in test and run
# INSPECTOR=true bin/rspec
Capybara.default_max_wait_time = 5
Capybara.disable_animation = true
module CapybaraHelp... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/warden_helpers.rb | Ruby | bsd-3-clause | 99 | main | 634 | module WardenHelpers
def login_admin_user(admin_user = FactoryBot.create(:admin_user))
login_as(admin_user, scope: :admin_user)
admin_user
end
alias_method :login_as_admin, :login_admin_user
def login_user(user = FactoryBot.create(:user))
login_as(user, scope: :user)
user
end
alias_method :... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/support/generator_example_group.rb | Ruby | bsd-3-clause | 99 | main | 1,850 | require "fileutils"
require "rails/generators/testing/behavior"
# RSpec rails provides example groups for system tests, controller tests, model
# tests etc., each of which act as thin wrappers for Rails test case classes
# where possible. However, there is no built-in example group for generator
# tests.
module Gener... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/routing/share/snippets_routing_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,095 | require "rails_helper"
RSpec.describe Share::SnippetsController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(get: "/share/snippets").to route_to("share/snippets#index")
end
it "routes to #new" do
expect(get: "/share/snippets/new").to route_to("share/snippets#new")... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/home_spec.rb | Ruby | bsd-3-clause | 99 | main | 567 | require "rails_helper"
RSpec.describe "Home", type: :system do
it "displays the home page" do
Page.upsert_collection_from_sitepress!
visit "/"
expect(document).to have_content("Joy of Rails")
expect(document).to have_content("More articles")
end
it "doesn’t break if an article gets moved" do
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/articles_spec.rb | Ruby | bsd-3-clause | 99 | main | 2,305 | require "rails_helper"
RSpec.describe "Articles", type: :system do
it "displays articles" do
visit "/articles"
expect(document).to have_content("Articles")
end
it "displays a single article" do
article = FactoryBot.create(:page, :published, request_path: "/articles/custom-color-schemes-with-ruby-on... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/searches_spec.rb | Ruby | bsd-3-clause | 99 | main | 618 | require "rails_helper"
RSpec.describe "Searches", type: :system do
it "show search results" do
article = FactoryBot.create(:page, :published, request_path: "/pwa-showcase")
article.update_in_search_index
visit root_path
find("#search-button").click
fill_in :query, with: "Progressive Web Apps"
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/newsletters_spec.rb | Ruby | bsd-3-clause | 99 | main | 754 | require "rails_helper"
RSpec.describe "Newsletters", type: :system do
it "renders empty list" do
visit newsletters_path
expect(document).to have_content("No newsletters")
end
it "renders list of published newsletters" do
unsent = FactoryBot.create_list(:newsletter, 2)
sent = FactoryBot.create_l... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/pwa_showcase_spec.rb | Ruby | bsd-3-clause | 99 | main | 812 | require "rails_helper"
RSpec.describe "PWA Showcase", type: :system do
it "hides PWA Showcase navigation" do
visit "/"
expect(document).not_to have_link("Progress Web Apps on Rails Showcase")
end
it "renders the Install to Homescreen button" do
visit "/pwa-showcase"
expect(document).to have_bu... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/topics_spec.rb | Ruby | bsd-3-clause | 99 | main | 756 | require "rails_helper"
RSpec.describe "Topics", type: :system do
it "displays the topics and provides navigation links" do
Page.upsert_collection_from_sitepress!(limit: 3)
expect(Page.count).to eq(3)
Page.find_each do |model|
model.topics = FactoryBot.create_list(:topic, 2, :approved)
model... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/author/polls_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,556 | require "rails_helper"
RSpec.describe "Polls", type: :system do
it "allows an authenticated user to create a poll" do
author = FactoryBot.create(:user)
Flipper.enable(:polls, author)
poll = FactoryBot.create(:poll, author:, title: "Color poll")
question = FactoryBot.create(:polls_question, poll:, bod... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/author/snippets_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,479 | require "rails_helper"
RSpec.describe "Snippets", type: :system do
before do
Flipper.enable(:snippets)
end
it "can create and edit a snippet" do
login_as_user
visit author_snippets_path
click_link "New Snippet"
fill_in "snippet[filename]", with: "app/models/blog.rb"
select "Ruby", fro... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/users/registrations_spec.rb | Ruby | bsd-3-clause | 99 | main | 2,432 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Registrations", type: :system do
before do
Flipper[:user_registration].enable
end
it "allows a new user to register for an account" do
visit new_users_registration_path
fill_in "Email address", with: "user1@example.com"
fill_... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/users/confirmations_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,379 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Confirmations", type: :system do
before do
Flipper[:user_registration].enable
end
it "allows a user to confirm their email address" do
user = FactoryBot.create(:user)
expect(user).not_to be_confirmed
EmailConfirmationNotifier... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/users/sessions_spec.rb | Ruby | bsd-3-clause | 99 | main | 2,278 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Sessions", type: :system do
before do
Flipper[:user_registration].enable
end
it "allows a confirmed user to sign in by password" do
user = FactoryBot.create(:user, :confirmed, password: "password", password_confirmation: "password")
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/users/passwords_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,928 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Passwords", type: :system do
before do
Flipper[:user_registration].enable
end
it "allows a user to reset their password" do
user = FactoryBot.create(:user, :confirmed)
visit new_users_password_path
fill_in "Email address", w... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/users/newsletter_subscriptions_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,628 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Newsletter subscriptions", type: :system do
it "allows a user to subscribe to the newsletter" do
visit root_path
click_button "Subscribe"
expect(document).to have_content("Email can't be blank")
fill_in "user[email]", with: "hell... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/mastering-custom-configuration-in-rails_spec.rb | Ruby | bsd-3-clause | 99 | main | 290 | require "rails_helper"
RSpec.describe "Mastering Custom Configuration in Rails", type: :system do
it "displays the article content" do
visit "/articles/mastering-custom-configuration-in-rails"
expect(document).to have_content "Mastering Custom Configuration in Rails"
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/web-push-notifications-from-rails_spec.rb | Ruby | bsd-3-clause | 99 | main | 286 | require "rails_helper"
RSpec.describe "Mastering Custom Configuration in Rails", type: :system do
it "displays the article content" do
visit "/articles/web-push-notifications-from-rails"
expect(document).to have_content "Sending Web Push Notifications from Rails"
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/introducing_joy_of_rails_spec.rb | Ruby | bsd-3-clause | 99 | main | 464 | require "rails_helper"
RSpec.describe "Introducing Joy of Rails", type: :system do
it "displays the article content" do
visit "/articles/introducing-joy-of-rails"
expect(document).to have_content "Introducing Joy of Rails"
page.driver.scroll_to(0, -10000)
within "#new_examples_counter" do
exp... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/custom_color_schemes_with_ruby_on_rails_spec.rb | Ruby | bsd-3-clause | 99 | main | 924 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Custom Color Schemes with Ruby on Rails", type: :system do
let(:curated_colors) do
FactoryBot.create_list(:color_scheme, 3)
end
before do
allow(ColorScheme).to receive(:curated).and_return(curated_colors)
end
it "user can selecte... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/what-you-need-to-know-about-sqlite_spec.rb | Ruby | bsd-3-clause | 99 | main | 663 | require "rails_helper"
RSpec.describe "What you need to know about SQLite", type: :system do
it "displays the article content if primary poll author does not exist" do
visit "/articles/what-you-need-to-know-about-sqlite"
expect(document).to have_content "What you need to know about SQLite"
end
it "disp... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/how_to_render_css_dynamically_in_rails_spec.rb | Ruby | bsd-3-clause | 99 | main | 805 | require "rails_helper"
RSpec.describe "How to Render CSS Dynamically in Rails", type: :system do
let(:curated_colors) do
FactoryBot.create_list(:color_scheme, 3)
end
before do
allow(ColorScheme).to receive(:curated).and_return(curated_colors)
end
it "provides a color scheme preview" do
visit "/... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/simple-trick-to-understand-ruby-lazy-enumerator_spec.rb | Ruby | bsd-3-clause | 99 | main | 676 | require "rails_helper"
RSpec.describe "A simple trick to understand Ruby’s lazy enumerator", type: :system do
it "displays the article content" do
visit "/articles/simple-trick-to-understand-ruby-lazy-enumerator"
expect(document).to have_content "A simple trick to understand Ruby’s lazy enumerator"
end
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/add_your_rails_app_to_the_home_screen_spec.rb | Ruby | bsd-3-clause | 99 | main | 284 | require "rails_helper"
RSpec.describe "Add your Rails App to the Home Screen", type: :system do
it "displays the article content" do
visit "/articles/add-your-rails-app-to-the-home-screen"
expect(document).to have_content "Add your Rails app to the Home Screen"
end
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/content/zee-kitchen-sink-permanent-draft_spec.rb | Ruby | bsd-3-clause | 99 | main | 626 | require "rails_helper"
RSpec.describe "Zee Kitchen Sink Permanent Draft", type: :system do
it "displays the article content" do
FactoryBot.create(:user, :primary_author)
Page.upsert_page_by_request_path! "/articles/zee-kitchen-sink-permanent-draft"
visit "/articles/zee-kitchen-sink-permanent-draft"
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/settings/syntax_highlights_spec.rb | Ruby | bsd-3-clause | 99 | main | 981 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Customize Syntax Highlighting", type: :system do
it "user can selected a curated syntax highlight" do
visit root_path
click_link "Syntax Highlight"
expect(document).to have_css("link[data-syntax-highlight*=dracula]", visible: false)
... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/settings/color_schemes_spec.rb | Ruby | bsd-3-clause | 99 | main | 764 | # frozen_string_literal: true
require "rails_helper"
RSpec.describe "Customize Color Scheme", type: :system do
let(:curated_colors) do
FactoryBot.create_list(:color_scheme, 3)
end
before do
allow(ColorScheme).to receive(:curated).and_return(curated_colors)
end
it "user can selected a curated color... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/share/polls_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,908 | require "rails_helper"
RSpec.describe "Polls", type: :system do
it "allows an anonymous user to vote" do
poll = FactoryBot.create(:poll, author: FactoryBot.create(:user), title: "Color poll")
question = FactoryBot.create(:polls_question, poll:, body: "What is your favorite color?")
answer1 = FactoryBot.c... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/share/snippets_spec.rb | Ruby | bsd-3-clause | 99 | main | 674 | require "rails_helper"
RSpec.describe "Snippets", type: :system do
before do
Flipper.enable(:snippets)
end
it "can attach a screenshot" do
snippet = FactoryBot.create(:snippet, author: login_as_user)
visit share_snippet_path(snippet)
click_link "Share"
expect(document).to have_content("Do... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/admin/newsletter_spec.rb | Ruby | bsd-3-clause | 99 | main | 3,019 | require "rails_helper"
RSpec.describe "Admin for Newsletters", type: :system do
it "create and edit a newsletter" do
login_as_admin
visit admin_newsletters_path
click_on "New newsletter"
fill_in "Title", with: "Welcome to Joy of Rails!"
fill_in "Content", with: <<~MARKDOWN
# Welcome to ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/admin_users/sessions_spec.rb | Ruby | bsd-3-clause | 99 | main | 1,352 | require "rails_helper"
RSpec.describe "AdminUser sessions", type: :system do
it "signs in admin_user" do
admin_user = FactoryBot.create(:admin_user)
visit new_admin_users_session_path
expect(document).to have_text("Sign in to your Admin Account")
fill_in "Email", with: admin_user.email
fill_in ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/examples/counters_spec.rb | Ruby | bsd-3-clause | 99 | main | 833 | require "rails_helper"
RSpec.describe "Examples Counter", type: :system do
it "maintains a daily click count" do
visit examples_counters_path
within "#new_examples_counter" do
assert_count(0)
click_button "Increment"
assert_count(1)
click_button "Decrement"
click_button "Dec... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | spec/system/examples/posts_spec.rb | Ruby | bsd-3-clause | 99 | main | 3,247 | require "rails_helper"
RSpec.describe "Examples: Posts", type: :system do
before do
user = login_user
Flipper.enable(:example_posts, user)
end
it "renders the form inputs dynamically and retains previously entered values" do
visit examples_posts_path
click_link "New Post"
within "main form... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/application.rb | Ruby | bsd-3-clause | 99 | main | 2,057 | # frozen_string_literal: true
require_relative "boot"
require "rails"
require "dotenv/load" if Rails.env.development? || Rails.env.test?
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_contr... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/ci.rb | Ruby | bsd-3-clause | 99 | main | 756 | # Run using bin/ci
CI.run do
step "Setup", "bin/setup --skip-server"
step "Style: ERB", "bin/erb_lint --lint-all"
step "Style: Ruby", "bin/standardrb --parallel"
step "Security: Gem audit", "bin/bundler-audit"
step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-o... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/routes.rb | Ruby | bsd-3-clause | 99 | main | 38,926 | # == Route Map
#
# Prefix Verb URI Pattern Controller#Action
# /assets ... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/warden.rb | Ruby | bsd-3-clause | 99 | main | 618 | require "warden"
require_relative "../../app/lib/warden_extensions/setup"
require_relative "../../app/lib/warden_extensions/strategies/password"
require_relative "../../app/lib/warden_extensions/strategies/magic_session"
Rails.configuration.middleware.use Warden::Manager do |manager|
manager.failure_app = proc { |en... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/content_security_policy.rb | Ruby | bsd-3-clause | 99 | main | 1,823 | # Be sure to restart your server when you modify this file.
# Define an application-wide content security policy.
# See the Securing Rails Applications Guide for more information:
# https://guides.rubyonrails.org/security.html#content-security-policy-header
# Rails.application.configure do
# config.content_security... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/assets.rb | Ruby | bsd-3-clause | 99 | main | 598 | # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
Rails.application.config... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/postmark.rb | Ruby | bsd-3-clause | 99 | main | 357 | Rails.application.configure do
config.x.postmark.api_token = Rails.application.credentials.dig(:postmark, :api_token) || "POSTMARK_API_TEST"
config.action_mailer.postmark_settings = {api_token: config.x.postmark.api_token}
if Rails.env.local? && ENV["ENABLE_POSTMARK_IN_DEV"] == "true"
config.action_mailer.d... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/new_framework_defaults_8_0.rb | Ruby | bsd-3-clause | 99 | main | 1,176 | # Be sure to restart your server when you modify this file.
#
# This file eases your Rails 8.0 framework defaults upgrade.
#
# Uncomment each configuration one by one to switch to the new default.
# Once your application is ready to run with all new defaults, you can remove
# this file and set the `config.load_defaults... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/yjit.rb | Ruby | bsd-3-clause | 99 | main | 410 | # Automatically enable YJIT if running Ruby 3.3 or newer,
# as it brings very sizeable performance improvements.
# Many users reported 15-25% improved latency.
# If you are deploying to a memory-constrained environment,
# you may want to delete this file, but otherwise, it's free
# performance.
if defined? RubyVM::YJI... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/openai.rb | Ruby | bsd-3-clause | 99 | main | 254 | OpenAI.configure do |config|
config.access_token = Rails.application.credentials.dig(:openai, :access_token) || ""
config.organization_id = Rails.application.credentials.dig(:openai, :organization_id) || ""
config.log_errors = Rails.env.local?
end |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/emails.rb | Ruby | bsd-3-clause | 99 | main | 693 | Rails.application.configure do
config.x.emails.transactional_from_address = credentials.dig(:emails, :transactional_from_address) || "hello@example.com"
config.x.emails.transactional_from_name = credentials.dig(:emails, :transactional_from_name) || "Joy of Rails"
config.x.emails.broadcast_from_address = credentia... |
github | joyofrails/joyofrails.com | https://github.com/joyofrails/joyofrails.com | config/initializers/invisible_captcha.rb | Ruby | bsd-3-clause | 99 | main | 358 | require "invisible_captcha"
InvisibleCaptcha.setup do |config|
# We need to deal with invisible captcha for specs
# https://github.com/markets/invisible_captcha?tab=readme-ov-file#testing-your-controllers
if Rails.env.test?
config.timestamp_enabled = false
config.spinner_enabled = false
config.honeyp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.