moves Sms model to Verification namespace
This commit is contained in:
@@ -6,11 +6,11 @@ class Verification::SmsController < ApplicationController
|
|||||||
skip_authorization_check
|
skip_authorization_check
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@sms = Sms.new(phone: params[:phone])
|
@sms = Verification::Sms.new(phone: params[:phone])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@sms = Sms.new(sms_params.merge(user: current_user))
|
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
|
||||||
if @sms.save
|
if @sms.save
|
||||||
redirect_to edit_sms_path, notice: t('verification.sms.create.flash.success')
|
redirect_to edit_sms_path, notice: t('verification.sms.create.flash.success')
|
||||||
else
|
else
|
||||||
@@ -19,11 +19,11 @@ class Verification::SmsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@sms = Sms.new
|
@sms = Verification::Sms.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@sms = Sms.new(sms_params.merge(user: current_user))
|
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
|
||||||
if @sms.verify?
|
if @sms.verify?
|
||||||
current_user.update(confirmed_phone: current_user.unconfirmed_phone)
|
current_user.update(confirmed_phone: current_user.unconfirmed_phone)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class Sms
|
class Verification::Sms
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
|
||||||
attr_accessor :user, :phone, :confirmation_code
|
attr_accessor :user, :phone, :confirmation_code
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<%= form_for sms, url: sms_path do |f| %>
|
<%= form_for sms, as: "sms", url: sms_path do |f| %>
|
||||||
<%= render 'shared/errors', resource: sms %>
|
<%= render 'shared/errors', resource: sms %>
|
||||||
<%= f.hidden_field :phone %>
|
<%= f.hidden_field :phone %>
|
||||||
<%= f.submit t('verification.sms.form.submit_button') %>
|
<%= f.submit t('verification.sms.form.submit_button') %>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<h1 class="inline-block"><%= t('verification.sms.edit.title') %></h1>
|
<h1 class="inline-block"><%= t('verification.sms.edit.title') %></h1>
|
||||||
|
|
||||||
<%= form_for @sms, url: sms_path, method: :put do |f| %>
|
<%= form_for @sms, as: "sms", url: sms_path, method: :put do |f| %>
|
||||||
<p><%= @error %></p>
|
<p><%= @error %></p>
|
||||||
<%= f.text_field :confirmation_code %>
|
<%= f.text_field :confirmation_code %>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<h1 class="inline-block"><%= t('verification.sms.new.title') %></h1>
|
<h1 class="inline-block"><%= t('verification.sms.new.title') %></h1>
|
||||||
|
|
||||||
<%= form_for @sms, url: sms_path do |f| %>
|
<%= form_for @sms, as: "sms", url: sms_path do |f| %>
|
||||||
<%= render 'shared/errors', resource: @sms %>
|
<%= render 'shared/errors', resource: @sms %>
|
||||||
|
|
||||||
<%= f.text_field :phone %>
|
<%= f.text_field :phone %>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<%= verified_user.phone %>
|
<%= verified_user.phone %>
|
||||||
</span>
|
</span>
|
||||||
<span style="float:left;padding-left:30px">
|
<span style="float:left;padding-left:30px">
|
||||||
<%= render '/verification/sms/form', sms: Sms.new(phone: verified_user.phone) %>
|
<%= render '/verification/sms/form', sms: Verification::Sms.new(phone: verified_user.phone) %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<br/><br/><br/>
|
<br/><br/><br/>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ FactoryGirl.define do
|
|||||||
postal_code "28013"
|
postal_code "28013"
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :sms do
|
factory :verification_sms, class: Verification::Sms do
|
||||||
phone "699999999"
|
phone "699999999"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Sms do
|
describe Verification::Sms do
|
||||||
it "should be valid" do
|
it "should be valid" do
|
||||||
sms = build(:sms)
|
sms = build(:verification_sms)
|
||||||
expect(sms).to be_valid
|
expect(sms).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should validate uniqness of phone" do
|
it "should validate uniqness of phone" do
|
||||||
user = create(:user, confirmed_phone: "699999999")
|
user = create(:user, confirmed_phone: "699999999")
|
||||||
sms = Sms.new(phone: "699999999")
|
sms = Verification::Sms.new(phone: "699999999")
|
||||||
expect(sms).to_not be_valid
|
expect(sms).to_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user