diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4df8e514..71e5f141 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 diff --git a/spec/requests/preferences_spec.rb b/spec/requests/preferences_spec.rb new file mode 100644 index 00000000..82e00be9 --- /dev/null +++ b/spec/requests/preferences_spec.rb @@ -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