* Move app_domain from env var to siteconfig *within app area* * Fix SiteConfig * Don't change URL.domain yet * Not use in fastly cache purge yet * Session store magoo * Revert domain issue * Add SetCookie middleware * Temporarily remove cookie middleware and release tasks * Re-enable SetCookieDomain * Add some more comments, get it ready for testing * Remove host from url options and temporarily show errors * Allow forwarded host to be cookie * Fix typo * Change invalidAuthenticityToken * Properly set app domain * Proper Fastly cache * Remove config.app_domain * Remove config.app_domain * Explicitely set remember_user_token * More play with cookies * Fiddle with remember_user_token * Add remember_user_token changes * Monkeypatch devise * Sessions controller * Include rememberable * Include rememberable * Proper cookie monkeypatch * Proper cookie monkeypatch * Proper cookie monkeypatch * Remove extra cookie code * User sign in tweak * Close the loop * Experiment with carrierwave public_url * Finalize carrierwave monkeypatch * Remove async controller specs * Change some tests * Update domain test * Remove temporary production.rb change * modify cookie logic * Remove unneeded changes * Remove unneeded changes * Explicitely pass host * Fix linting * Fix social image test * Add some cookie tests * Modify article url * Fix canonical urls * Fix typo * Remove sessions controller * Remove devise monkeypatch * Add monkeypatch * Remove elsif * Update spec/helpers/application_helper_spec.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Adjust remember_cookie_sync * Remember user token experimentation * Fiddle with devise * Properly configure devise * Fix typo * Fix formatting issue * Add comment about middleware * Fix typo Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com> * Remove commented-out code Co-authored-by: Michael Kohl <citizen428@dev.to> Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
98 lines
3 KiB
Ruby
98 lines
3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe URL, type: :lib do
|
|
before do
|
|
allow(ApplicationConfig).to receive(:[]).with("APP_PROTOCOL").and_return("https://")
|
|
allow(ApplicationConfig).to receive(:[]).with("APP_DOMAIN").and_return("test.forem.cloud")
|
|
SiteConfig.app_domain = "dev.to"
|
|
end
|
|
|
|
describe ".protocol" do
|
|
it "returns the value of APP_PROTOCOL env variable" do
|
|
expect(described_class.protocol).to eq(ApplicationConfig["APP_PROTOCOL"])
|
|
end
|
|
end
|
|
|
|
describe ".domain" do
|
|
it "returns the value of SiteConfig" do
|
|
expect(described_class.domain).to eq(SiteConfig.app_domain)
|
|
end
|
|
end
|
|
|
|
describe ".url" do
|
|
it "creates the correct base app URL" do
|
|
expect(described_class.url).to eq("https://dev.to")
|
|
end
|
|
|
|
it "creates a URL with a path" do
|
|
expect(described_class.url("admin")).to eq("https://dev.to/admin")
|
|
end
|
|
|
|
it "creates the correct URL even if the path starts with a slash" do
|
|
expect(described_class.url("/admin")).to eq("https://dev.to/admin")
|
|
end
|
|
|
|
it "works when called with an URI object" do
|
|
uri = URI::Generic.build(path: "admin", fragment: "test")
|
|
expect(described_class.url(uri)).to eq("https://dev.to/admin#test")
|
|
end
|
|
end
|
|
|
|
describe ".article" do
|
|
let(:article) { build(:article, path: "/username1/slug") }
|
|
|
|
it "returns the correct URL for an article" do
|
|
expect(described_class.article(article)).to eq("https://dev.to#{article.path}")
|
|
end
|
|
end
|
|
|
|
describe ".comment" do
|
|
let(:comment) { build(:comment) }
|
|
|
|
it "returns the correct URL for a comment" do
|
|
expect(described_class.comment(comment)).to eq("https://dev.to#{comment.path}")
|
|
end
|
|
end
|
|
|
|
describe ".reaction" do
|
|
it "returns the correct URL for an article's reaction" do
|
|
article = build(:article, path: "/username1/slug")
|
|
reaction = build(:reaction, reactable: article)
|
|
expect(described_class.reaction(reaction)).to eq("https://dev.to#{article.path}")
|
|
end
|
|
|
|
it "returns the correct URL for a comment's reaction" do
|
|
comment = build(:comment)
|
|
reaction = build(:reaction, reactable: comment)
|
|
expect(described_class.reaction(reaction)).to eq("https://dev.to#{comment.path}")
|
|
end
|
|
end
|
|
|
|
describe ".user" do
|
|
let(:user) { build(:user) }
|
|
|
|
it "returns the correct URL for a user" do
|
|
expect(described_class.user(user)).to eq("https://dev.to/#{user.username}")
|
|
end
|
|
end
|
|
|
|
describe ".organization" do
|
|
let(:organization) { build(:organization) }
|
|
|
|
it "returns the correct URL for a user" do
|
|
expect(described_class.user(organization)).to eq("https://dev.to/#{organization.slug}")
|
|
end
|
|
end
|
|
|
|
describe ".tag" do
|
|
let(:tag) { build(:tag) }
|
|
|
|
it "returns the correct URL for a tag with no page" do
|
|
expect(described_class.tag(tag)).to eq("https://dev.to/t/#{tag.name}")
|
|
end
|
|
|
|
it "returns the correct URL for a tag" do
|
|
expect(described_class.tag(tag, 2)).to eq("https://dev.to/t/#{tag.name}/page/2")
|
|
end
|
|
end
|
|
end
|