Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require "spec_helper"
before do
request.env["devise.mapping"] = Devise.mappings[:user]
end
let(:valid_params) {
{
user: {
username: "jdoe",
email: "jdoe@example.com",
password: "password",
password_confirmation: "password"
describe "#check_registrations_open_or_valid_invite!" do
it "redirects #new to the login page" do
expect(flash[:error]).to eq(I18n.t("registrations.closed"))
expect(response).to redirect_to new_user_session_path
it "redirects #create to the login page" do
post :create, valid_params
expect(flash[:error]).to eq(I18n.t("registrations.closed"))
expect(response).to redirect_to new_user_session_path
it "does not redirect if there is a valid invite token" do
code = InvitationCode.create(user: bob)
get :new, invite: {token: code.token}
it "does redirect if there is an invalid invite token" do
get :new, invite: {token: "fssdfsd"}
expect(response).to redirect_to new_user_session_path
end
it "does redirect if there are no invites available with this code" do
code = InvitationCode.create(user: bob)
code.update_attributes(count: 0)
get :new, invite: {token: code.token}
expect(response).to redirect_to new_user_session_path
end
it "does redirect when invitations are closed now" do
code = InvitationCode.create(user: bob)
AppConfig.settings.invitations.open = false
get :new, invite: {token: code.token}
expect(response).to redirect_to new_user_session_path
end
it "does not redirect when the registration is open" do
AppConfig.settings.enable_registrations = true
code = InvitationCode.create(user: bob)
code.update_attributes(count: 0)
get :new, invite: {token: code.token}
expect(response).not_to be_redirect
Jason Robinson
a validé
render_views
context "with valid parameters" do
it "creates a user" do
get :create, valid_params
get :create, valid_params
get :create, valid_params
expect(flash[:notice]).not_to be_blank
it "redirects to the home path" do
get :create, valid_params
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
expect(response.location).to match(/^#{getting_started_url}$/)
end
context "with invite code" do
it "reduces number of available invites when the registration is closed" do
AppConfig.settings.enable_registrations = false
code = InvitationCode.create(user: bob)
expect {
get :create, valid_params.merge(invite: {token: code.token})
}.to change { code.reload.count }.by(-1)
end
it "doesn't reduce number of available invites when the registration is open" do
code = InvitationCode.create(user: bob)
expect {
get :create, valid_params.merge(invite: {token: code.token})
}.not_to change { code.reload.count }
end
it "links inviter with the user" do
code = InvitationCode.create(user: bob)
post :create, valid_params.merge(invite: {token: code.token})
expect(User.find_by(username: "jdoe").invited_by).to eq(bob)
end
context "with invalid parameters" do
let(:invalid_params) { valid_params.deep_merge(user: {password_confirmation: "baddword"}) }
it "does not create a user" do
expect { get :create, invalid_params }.not_to change(User, :count)
end
it "does not create a person" do
expect { get :create, invalid_params }.not_to change(Person, :count)
end
get :create, invalid_params
it "sets the flash error" do
get :create, invalid_params
expect(flash[:error]).not_to be_blank
end
it "doesn't reduce number of available invites" do
AppConfig.settings.enable_registrations = false
code = InvitationCode.create(user: bob)
expect {
get :create, invalid_params.merge(invite: {token: code.token})
}.not_to change { code.reload.count }
end
Jason Robinson
a validé
it "renders new" do
get :create, invalid_params
Jason Robinson
a validé
expect(response).to render_template("registrations/new")
end
Jason Robinson
a validé
it "keeps invalid params in form" do
get :create, invalid_params
Jason Robinson
a validé
expect(response.body).to match /jdoe@example.com/m
end
end