Don't use "dummy" anywhere

This commit is contained in:
Marcin Kulik 2014-10-05 18:25:49 +02:00
parent c4a4961553
commit ca156564f5
7 changed files with 15 additions and 17 deletions

View File

@ -31,7 +31,7 @@ class AsciicastParams
token = attributes['user_token']
username = attributes['username']
User.for_api_token(token) || User.create_dummy(token, username)
User.for_api_token(token) || User.create_with_token(token, username)
end
end

View File

@ -45,14 +45,12 @@ class User < ActiveRecord::Base
where(auth_token: auth_token).first
end
def self.create_dummy(token, username)
def self.create_with_token(token, username)
return nil if token.blank?
username = nil if username.blank?
transaction do |tx|
user = User.new
user.temporary_username = username
user.save!
user = User.create!(temporary_username: username)
user.api_tokens.create!(token: token)
user
end

View File

@ -94,7 +94,7 @@ describe UsersController do
subject
end
context "when real user username given" do
context "when confirmed user username given" do
let(:user) { create(:user) }
it 'renders "show" template' do
@ -102,8 +102,8 @@ describe UsersController do
end
end
context "when dummy user username given" do
let(:user) { create(:dummy_user) }
context "when unconfirmed user username given" do
let(:user) { create(:unconfirmed_user) }
it "responds with 404" do
expect(subject).to be_not_found

View File

@ -11,7 +11,7 @@ FactoryGirl.define do
sequence(:email) { |n| "foo#{n}@bar.com" }
end
factory :dummy_user, class: User do
factory :unconfirmed_user, class: User do
sequence(:temporary_username) { generate(:username) }
end
end

View File

@ -42,7 +42,7 @@ describe ApiToken do
allow(user).to receive(:merge_to)
end
context "when source user is a dummy user" do
context "when source user is unconfirmed user" do
before do
allow(user).to receive(:confirmed?) { false }
end

View File

@ -54,14 +54,14 @@ describe AsciicastParams do
it { should eq(expected_attrs) }
context "when given api token is not found" do
let(:expected_user) { dummy_user }
let(:dummy_user) { User.new }
let(:expected_user) { unconfirmed_user }
let(:unconfirmed_user) { User.new }
before do
allow(User).to receive(:for_api_token).
with('f33e6188-f53c-11e2-abf4-84a6c827e88b') { nil }
allow(User).to receive(:create_dummy).
with('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill') { dummy_user }
allow(User).to receive(:create_with_token).
with('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill') { unconfirmed_user }
end
it { should eq(expected_attrs) }

View File

@ -82,7 +82,7 @@ describe User do
let(:email) { nil }
before do
create(:dummy_user, email: nil)
create(:unconfirmed_user, email: nil)
end
it { should be(nil) }
@ -122,8 +122,8 @@ describe User do
end
end
describe '.create_dummy' do
subject { described_class.create_dummy(token, username) }
describe '.create_with_token' do
subject { described_class.create_with_token(token, username) }
let(:token) { 'f33e6188-f53c-11e2-abf4-84a6c827e88b' }
let(:username) { 'somerandomguy' }