Skip to content

Commit

Permalink
💡 FM-4 : Availed identifier option when facemock user new
Browse files Browse the repository at this point in the history
  • Loading branch information
ogawatti committed Sep 9, 2014
1 parent e233707 commit b146d24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/facemock/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class User < Database::Table

def initialize(options={})
opts = Hashie::Mash.new(options)
@id = (opts.id.to_i > 0) ? opts.id.to_i : ("10000" + (0..9).to_a.shuffle[0..10].join).to_i
id = opts.id || opts.identifier
@id = (id.to_i > 0) ? id.to_i : ("10000" + (0..9).to_a.shuffle[0..10].join).to_i
@name = opts.name || rand(36**10).to_s(36)
@email = opts.email || name.gsub(" ", "_") + "@example.com"
@password = opts.password || rand(36**10).to_s(36)
@installed = opts.installed || false
@access_token = opts.access_token || Digest::SHA512.hexdigest(identifier.to_s)
@access_token = opts.access_token || rand(36**255).to_s(36)
app_id = opts.application_id.to_i
@application_id = (app_id > 0) ? app_id : nil
@created_at = opts.created_at
Expand Down
19 changes: 18 additions & 1 deletion spec/facemock/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

describe '.size' do
subject { Facemock::User.new.access_token.size }
it { is_expected.to eq 128 }
it { is_expected.to be <= 255 }
end
end

Expand All @@ -126,6 +126,23 @@
end
end

# TODO : DOING
context 'with identifier option' do
before { @opts = { identifier: 100010000000000 } }
subject { Facemock::User.new(@opts) }
it { is_expected.to be_kind_of Facemock::User }

describe '.id' do
subject { Facemock::User.new(@opts).id }
it { is_expected.to eq @opts[:identifier] }
end

describe '.identifier' do
subject { Facemock::User.new(@opts).identifier }
it { is_expected.to eq @opts[:identifier] }
end
end

context 'with application_id option but it is not integer' do
before { @opts = { application_id: "test_id" } }
subject { Facemock::User.new(@opts) }
Expand Down

0 comments on commit b146d24

Please sign in to comment.