Sha256: 19d47825ff0a45599783bf125c1870c5b69f94ed666c8c0fa95d6c5c7d475247

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe "Subscriptions", type: :feature do
  before do
    setup_site(FactoryGirl.create(:admin))
  end

  it "allows users to subscribe to a site" do
    expect(Storytime::Subscription.count).to eq(0)

    site = Storytime::Site.last
    email_address = "some_email_address@example.com"

    visit "/"
    click_link "#{I18n.t('layout.subscribe_to', site_name: site.title)}"
    fill_in "subscription_email", with: email_address
    click_button "Subscribe"

    expect(Storytime::Subscription.count).to eq(1)
    subscription = Storytime::Subscription.first

    expect(subscription.email).to eq(email_address)
    expect(subscription.token).to_not eq(nil)
    expect(subscription.subscribed?).to eq(true)
  end

  it "only allows users to unsubscribe with a proper token" do
    subscription_1 = FactoryGirl.create(:subscription, site: @current_site)
    token_1 = subscription_1.token

    subscription_2 = FactoryGirl.create(:subscription, site: @current_site)
    token_2 = subscription_2.token

    visit url_for([:unsubscribe_mailing_list, {:email => subscription_1.email, :t => token_2}])

    expect(page).to have_content(I18n.t('flash.subscriptions.destroy.fail'))
    expect(subscription_1.subscribed?).to eq(true)

    visit url_for([:unsubscribe_mailing_list, {:email => subscription_1.email, :t => token_1}])

    expect(page).to have_content(I18n.t('flash.subscriptions.destroy.success'))

    subscription_1.reload
    subscription_2.reload

    expect(subscription_1.subscribed?).to eq(false)
    expect(subscription_2.subscribed?).to eq(true)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
storytime-2.1.6 spec/features/subscription_spec.rb
storytime-2.1.5 spec/features/subscription_spec.rb
storytime-2.1.4 spec/features/subscription_spec.rb
storytime-2.1.3 spec/features/subscription_spec.rb
storytime-2.1.2 spec/features/subscription_spec.rb
storytime-2.1.1 spec/features/subscription_spec.rb
storytime-2.1.0 spec/features/subscription_spec.rb