Sha256: fcbd3590e69d703d9a24348aa9fa30ad6e8010137e9a2d134a76d6ecb20cddd9

Contents?: true

Size: 993 Bytes

Versions: 10

Compression:

Stored size: 993 Bytes

Contents

require 'spec_helper'

describe Storytime::Subscription do
  describe "generate_token" do
    it "generates a token before creation" do
      subscription = FactoryGirl.build(:subscription)

      expect(subscription.token).to eq(nil)

      subscription.save

      expect(subscription.token).to_not eq(nil)
    end

    it "generates a token that can be regenerated from the email" do
      subscription = FactoryGirl.create(:subscription)
      token = subscription.token

      key = Rails.application.secrets.secret_key_base
      digest = OpenSSL::Digest.new('sha1')
      regenerated_token = OpenSSL::HMAC.hexdigest(digest, key, subscription.email)

      expect(token).to eq(regenerated_token)
    end
  end

  describe "unsubscribe!" do
    it "sets subscribed to false" do
      subscription = FactoryGirl.create(:subscription)

      expect(subscription.subscribed?).to eq(true)

      subscription.unsubscribe!

      expect(subscription.subscribed?).to eq(false)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
storytime-2.1.6 spec/models/subscription_spec.rb
storytime-2.1.5 spec/models/subscription_spec.rb
storytime-2.1.4 spec/models/subscription_spec.rb
storytime-2.1.3 spec/models/subscription_spec.rb
storytime-2.1.2 spec/models/subscription_spec.rb
storytime-2.1.1 spec/models/subscription_spec.rb
storytime-2.1.0 spec/models/subscription_spec.rb
storytime-2.0.0 spec/models/subscription_spec.rb
storytime-1.2.0 spec/models/subscription_spec.rb
storytime-1.1.1 spec/models/subscription_spec.rb