forked from lokka/lokka
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lokka#163 from takai/rspec_modernization
Modernize specs
- Loading branch information
Showing
9 changed files
with
85 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe "Snippet" do | ||
after { Snippet.destroy } | ||
|
||
context 'with id 1' do | ||
subject { Factory(:snippet, :id => 1) } | ||
subject { build :snippet, :id => 1 } | ||
its(:edit_link) { should eq('/admin/snippets/1/edit') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe 'Tag' do | ||
after do | ||
Tag.destroy | ||
Tagging.destroy | ||
end | ||
|
||
context "with name lokka" do | ||
before { @tag = Factory(:tag, :name => 'lokka') } | ||
subject { @tag } | ||
let!(:tag) { create :tag, :name => 'lokka' } | ||
subject { tag } | ||
|
||
its(:link) { should == '/tags/lokka/' } | ||
|
||
it 'Tag(name) should return the instance' do | ||
Tag('lokka').should eql(@tag) | ||
Tag('lokka').should eql(tag) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,61 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe "User" do | ||
after { User.destroy } | ||
describe User do | ||
subject { user } | ||
|
||
context "register" do | ||
before do | ||
@user = User.new( | ||
:name => 'Johnny', | ||
:email => 'johnny@example.com', | ||
:password => 'password', | ||
:password_confirmation => 'password' | ||
) | ||
end | ||
it "should be able to register a user" do | ||
@user.save.should be_true | ||
@user.name.should eq('Johnny') | ||
@user.email.should eq('johnny@example.com') | ||
end | ||
it "should not be able to register a user when name is blank" do | ||
@user.name = '' | ||
@user.save.should_not be_true | ||
end | ||
it "should not be able to register a user when email is blank" do | ||
@user.email = '' | ||
@user.save.should_not be_true | ||
shared_examples 'user with validation' do | ||
it 'saves successfully' do | ||
subject.save.should be_true | ||
end | ||
|
||
describe 'strip spaces' do | ||
it "should strip anteroposterior spaces" do | ||
@user.name = ' Johnny ' | ||
@user.save.should be_true | ||
@user.name.should eq('Johnny') | ||
end | ||
it "should not strip middle spaces" do | ||
@user.name = ' Johnny Depp ' | ||
@user.save.should be_true | ||
@user.name.should eq('Johnny Depp') | ||
context 'with blank name' do | ||
before { user.name = '' } | ||
|
||
it 'fails to save' do | ||
subject.save.should_not be_true | ||
end | ||
end | ||
end | ||
|
||
context "update" do | ||
before { @user = Factory(:user, :name => 'Johnny') } | ||
it "should be updated" do | ||
@user.name = 'Jack' | ||
@user.save.should be_true | ||
@user.name.should eq('Jack') | ||
end | ||
it "should not be updated when name is blank" do | ||
@user.name = '' | ||
@user.save.should_not be_true | ||
end | ||
it "should not be updated when email is blank" do | ||
@user.email = '' | ||
@user.save.should_not be_true | ||
context 'with blank email' do | ||
before { user.email = '' } | ||
|
||
it 'fails to save' do | ||
subject.save.should_not be_true | ||
end | ||
end | ||
|
||
describe 'strip spaces' do | ||
it "should strip anteroposterior spaces" do | ||
@user.name = ' Jack ' | ||
@user.save.should be_true | ||
@user.name.should eq('Jack') | ||
context 'with trailing whitespaces' do | ||
before do | ||
user.name = ' Johnny Depp ' | ||
end | ||
it "should not strip middle spaces" do | ||
@user.name = ' Jack Sparrow ' | ||
@user.save.should be_true | ||
@user.name.should eq('Jack Sparrow') | ||
|
||
it 'trims whitespace after save' do | ||
subject.save | ||
subject.name.should eq 'Johnny Depp' | ||
end | ||
end | ||
end | ||
|
||
context "guest" do | ||
before { @guest = GuestUser.new } | ||
it "not admin" do | ||
@guest.admin?.should be_false | ||
end | ||
it "permission leve 0" do | ||
@guest.permission_level.should eq(0) | ||
end | ||
describe '#save' do | ||
let(:user) do | ||
User.new(:name => 'Johnny', | ||
:email => 'johnny@example.com', | ||
:password => 'password', | ||
:password_confirmation => 'password') | ||
end | ||
it_behaves_like 'user with validation' | ||
end | ||
|
||
describe "#update" do | ||
let!(:user) { create :user, :name => 'Johnny' } | ||
|
||
it_behaves_like 'user with validation' | ||
end | ||
|
||
end | ||
|
||
describe GuestUser do | ||
it { should_not be_admin } | ||
its(:permission_level) { should eq 0 } | ||
end | ||
|