app_spec.rb
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'
describe App do
context 'validations' do
it 'requires a name' do
app = Factory.build(:app, :name => nil)
app.should_not be_valid
app.errors[:name].should include("can't be blank")
end
it 'requires unique names' do
Factory(:app, :name => 'Errbit')
app = Factory.build(:app, :name => 'Errbit')
app.should_not be_valid
app.errors[:name].should include('is already taken')
end
it 'requires unique api_keys' do
Factory(:app, :api_key => 'APIKEY')
app = Factory.build(:app, :api_key => 'APIKEY')
app.should_not be_valid
app.errors[:api_key].should include('is already taken')
end
end
context 'being created' do
it 'generates a new api-key' do
app = Factory.build(:app)
app.api_key.should be_nil
app.save
app.api_key.should_not be_nil
end
it 'generates a correct api-key' do
app = Factory(:app)
app.api_key.should match(/^[a-f0-9]{32}$/)
end
end
end