Skip to content

Commit

Permalink
add requests test for preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Jan 3, 2024
1 parent fe25224 commit 960e2dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
end

context "when confirmed" do
before { user.confirm } # confirm user's email manually which should run after_confirmation hook to create his preference
it "has a preference" do
user.confirm # confirm user's email manually which should run after_confirmation hook to create his preference
expect(user.preference).not_to be_nil
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/requests/preferences_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "rails_helper"

describe "/preferences", type: :request do
context "when not logged in" do
describe "GET /index" do
it "redirects the user" do
get preferences_url
expect(response).to have_http_status(:redirect)
end
end
end

context "when logged in" do
let(:user) { create(:user, preference: create(:preference)) }

before do
sign_in user
end

describe "GET /index" do
it "renders user preferences" do
get preferences_url
expect(response).to have_http_status(:ok)
expect(response.body).to include(I18n.t("preferences.index.notify_any_post_in_discussion"))
expect(response.body).to include(I18n.t("preferences.index.notify_new_discussion_on_story"))
expect(response.body).to include(I18n.t("preferences.index.notify_new_post_on_discussion"))
expect(response.body).to include(I18n.t("preferences.index.notify_new_story"))
end
end
end
end

0 comments on commit 960e2dc

Please sign in to comment.