docbrown/spec/models/shared_examples/user_subscription_sourceable_spec.rb
Alex 1890f393a2
[deploy] Add subscriber_email to user_subscriptions & more backend updates (#8723)
* Add migrations for subscriber_email column

* Add new schema

* Update relationships, specs, and factory

* Use unless index_exists? over if !index_exists?

* Fix typo in last fix for migration

* Rename authored_user_subscriptions

- to source_authored_user_subcriptions

* Add factory methods and specs

- UserSubscription.make
- UserSubscription.make_new
- Article.new_user_subscription
- Article.create_user_subscription

* Remove self and &

* Change make_new to build

* new_user_subscription --> build_user_subscription

* Come on, Travis
2020-06-18 14:40:08 -04:00

42 lines
1.4 KiB
Ruby

RSpec.shared_examples "UserSubscriptionSourceable" do
let(:model) { described_class }
let(:source) { create(model.to_s.underscore.to_sym) }
let(:subscriber) { create(:user) }
describe "#build_user_subscription" do
it "returns a new UserSubcription with the correct attributes" do
new_user_subscription = UserSubscription.new(
user_subscription_sourceable: source,
author_id: source.user_id,
subscriber_id: subscriber.id,
subscriber_email: subscriber.email,
)
factory_user_subscription = source.build_user_subscription(subscriber)
factory_user_subscription.attributes.each do |name, val|
expect(new_user_subscription[name]).to eq val
end
end
end
describe "#create_user_subscription" do
it "returns a created UserSubcription with the correct attributes" do
user_subscription_fields = %w[author_id subsciber_id subscriber_email user_subscription_sourceable_id user_susbcription_sourceable_type]
user_subscription = create(
:user_subscription,
user_subscription_sourceable: source,
author_id: source.user_id,
subscriber_id: subscriber.id,
subscriber_email: subscriber.email,
)
factory_user_subscription = source.create_user_subscription(subscriber)
user_subscription_fields.each do |field|
expect(factory_user_subscription[field]).to eq user_subscription[field]
end
end
end
end