User tokens for assigning asciicasts to users
parent
b7807c3f0d
commit
1ba9067551
@ -0,0 +1,5 @@
|
|||||||
|
class UserToken < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
validates :user, :token, :presence => true
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
class AddUserTokenToAsciicast < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :asciicasts, :user_token, :string
|
||||||
|
|
||||||
|
add_index :asciicasts, :user_token
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class CreateUserTokens < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :user_tokens do |t|
|
||||||
|
t.integer :user_id, :null => false
|
||||||
|
t.string :token, :null => false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :user_tokens, :user_id
|
||||||
|
add_index :user_tokens, :token
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,8 @@
|
|||||||
|
# Read about factories at http://github.com/thoughtbot/factory_girl
|
||||||
|
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :user_token do
|
||||||
|
association :user
|
||||||
|
token "some-token"
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"command": null,
|
||||||
|
"duration": 5.914434194564819,
|
||||||
|
"recorded_at": "Sun, 04 Mar 2012 16:43:52 +0000",
|
||||||
|
"shell": "/bin/zsh",
|
||||||
|
"term": {
|
||||||
|
"columns": 89,
|
||||||
|
"lines": 27,
|
||||||
|
"type": "rxvt-unicode-256color"
|
||||||
|
},
|
||||||
|
"title": null,
|
||||||
|
"uname": "Linux 3.2.6-3.fc16.x86_64 #1 SMP Mon Feb 13 20:35:42 UTC 2012 x86_64",
|
||||||
|
"user_token": "2b4b4e02-6613-11e1-9be5-00215c6bbb11"
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
@ -1,5 +1,53 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Asciicast do
|
describe Asciicast do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
it "has valid factory" do
|
||||||
|
Factory.build(:asciicast).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#save' do
|
||||||
|
let(:asciicast) { Factory.build(:asciicast, :user => user) }
|
||||||
|
|
||||||
|
context 'when no user given' do
|
||||||
|
let(:user) { nil }
|
||||||
|
|
||||||
|
it 'calls #assign_user' do
|
||||||
|
asciicast.should_receive(:assign_user)
|
||||||
|
asciicast.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user given' do
|
||||||
|
let(:user) { Factory.build(:user) }
|
||||||
|
|
||||||
|
it "doesn't call #assign_user" do
|
||||||
|
asciicast.should_not_receive(:assign_user)
|
||||||
|
asciicast.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#assign_user' do
|
||||||
|
let(:user) { Factory(:user) }
|
||||||
|
let(:asciicast) { Factory(:asciicast, :user => nil, :user_token => user_token) }
|
||||||
|
|
||||||
|
context 'when user exists with given token' do
|
||||||
|
let(:user_token) { Factory(:user_token, :user => user).token }
|
||||||
|
|
||||||
|
it 'assigns user and resets user_token' do
|
||||||
|
asciicast.assign_user
|
||||||
|
asciicast.user.should == user
|
||||||
|
asciicast.user_token.should be(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when there is no user with given token' do
|
||||||
|
let(:user_token) { 'some-foo-bar' }
|
||||||
|
|
||||||
|
it 'assigns user' do
|
||||||
|
asciicast.assign_user
|
||||||
|
asciicast.user.should be(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe UserToken do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in New Issue