* Refactor controller validations to model * Update specs and move current email validation back * Refactor #subscribed * Cleanup UserSubscriptions::Create service * Refactor service * Move source inside of call for clarity * Specs for UserSubscription::Create * Cleanup spec * Fix Article spec * Updated for subscriber_email * Add comment for explicitness of subscriber_email * Fix reference in comment...oops! * I know what I'm doing...sometimes...maybe * Rename CachChecker - Subscription to IsSubscribed * Use include vs eq in specs for error messages * attr_accessor --> attr_reader * Don't explicitly set nil * Rename Create service to CreateFromService * Use errors_as_sentence * Rename service to CreateFromControllerParams * Assign Struct to a new constant
21 lines
802 B
Ruby
21 lines
802 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe UserSubscriptions::IsSubscribedCacheChecker, type: :service do
|
|
let(:user) { create(:user) }
|
|
let(:article) { create(:article, :with_user_subscription_tag_role_user, with_user_subscription_tag: true) }
|
|
let(:params) { { source_type: article.class_name, source_id: article.id } }
|
|
|
|
it "checks if subscribed to a thing and returns true if they are" do
|
|
create(:user_subscription,
|
|
subscriber_id: user.id,
|
|
subscriber_email: user.email,
|
|
author_id: article.user_id,
|
|
user_subscription_sourceable: article)
|
|
|
|
expect(described_class.call(user, params)).to eq(true)
|
|
end
|
|
|
|
it "checks if subscribed to a thing and returns false if they are not" do
|
|
expect(described_class.call(user, params)).to eq(false)
|
|
end
|
|
end
|