-
Notifications
You must be signed in to change notification settings - Fork 319
/
subscriptions_controller_spec.rb
68 lines (48 loc) · 1.79 KB
/
subscriptions_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'rails_helper'
RSpec.describe SubscriptionsController, :type => :controller do
context "GET new" do
it "assigns a blank subscription to the view" do
get :new
expect(assigns(:subscription)).to be_a_new(Subscription)
end
end
context "POST create" do
it "redirects to pending subscriptions page" do
params = { subscription: { email: "[email protected]", start_on: "2014-12-31" } }
post :create, params
expect(response).to redirect_to(pending_subscriptions_path)
end
it "calls Subscription.create_and_request_confirmation(params)" do
email = "[email protected]"
start_on = "2015-02-28"
expect(Subscription).to receive(:create_and_request_confirmation)
.with({ email: email, start_on: start_on })
post :create, { subscription: { email: email, start_on: start_on } }
end
it "raises an error if missing params email" do
params = { subscription: { start_on: "2015-09-28" } }
expect do
post :create, params
end.to raise_error ActiveRecord::RecordInvalid
end
end
context "GET confirm" do
it "confirms the subscription" do
subscription = create(:subscription,
email: "[email protected]",
confirmation_token: Subscription.generate_confirmation_token
)
expect(subscription.confirmed?).to eq(false)
params = { confirmation_token: subscription.confirmation_token }
get :confirm, params
expect(subscription.reload.confirmed?).to eq(true)
expect(assigns(:subscription)).to eq(subscription)
end
it "responds with 404 Not Found for unknown confirmation token" do
params = { confirmation_token: "an-unknown-token" }
expect do
get :confirm, params
end.to raise_error ActiveRecord::RecordNotFound
end
end
end