moves Sms model to Verification namespace

This commit is contained in:
Juanjo Bazán
2015-08-29 12:17:27 +02:00
parent 50dcbcdf9b
commit e6fd62189b
8 changed files with 13 additions and 13 deletions

View File

@@ -6,11 +6,11 @@ class Verification::SmsController < ApplicationController
skip_authorization_check
def new
@sms = Sms.new(phone: params[:phone])
@sms = Verification::Sms.new(phone: params[:phone])
end
def create
@sms = Sms.new(sms_params.merge(user: current_user))
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
if @sms.save
redirect_to edit_sms_path, notice: t('verification.sms.create.flash.success')
else
@@ -19,11 +19,11 @@ class Verification::SmsController < ApplicationController
end
def edit
@sms = Sms.new
@sms = Verification::Sms.new
end
def update
@sms = Sms.new(sms_params.merge(user: current_user))
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
if @sms.verify?
current_user.update(confirmed_phone: current_user.unconfirmed_phone)

View File

@@ -1,4 +1,4 @@
class Sms
class Verification::Sms
include ActiveModel::Model
attr_accessor :user, :phone, :confirmation_code

View File

@@ -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 %>
<%= f.hidden_field :phone %>
<%= f.submit t('verification.sms.form.submit_button') %>

View File

@@ -3,7 +3,7 @@
<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>
<%= f.text_field :confirmation_code %>

View File

@@ -3,7 +3,7 @@
<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 %>
<%= f.text_field :phone %>

View File

@@ -32,7 +32,7 @@
<%= verified_user.phone %>
</span>
<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>
</li>
<br/><br/><br/>

View File

@@ -27,7 +27,7 @@ FactoryGirl.define do
postal_code "28013"
end
factory :sms do
factory :verification_sms, class: Verification::Sms do
phone "699999999"
end

View File

@@ -1,14 +1,14 @@
require 'rails_helper'
describe Sms do
describe Verification::Sms do
it "should be valid" do
sms = build(:sms)
sms = build(:verification_sms)
expect(sms).to be_valid
end
it "should validate uniqness of phone" do
user = create(:user, confirmed_phone: "699999999")
sms = Sms.new(phone: "699999999")
sms = Verification::Sms.new(phone: "699999999")
expect(sms).to_not be_valid
end