Skip to content

Commit

Permalink
Fixing specs for pages. Moving permalink related specs to model which…
Browse files Browse the repository at this point in the history
… is where they should be
  • Loading branch information
Frédéric de Villamil committed Mar 5, 2012
1 parent 7db1582 commit aae5924
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
8 changes: 0 additions & 8 deletions spec/controllers/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ def base_page(options={})
:published => true }.merge(options)
end

#TODO but this kind of action must move to model !
it "should use sanitize title to set page name" do
page = Factory.build(:page, :name => '')
page.name.should == page.title.to_permalink
Page.should_receive(:new).and_return(page)
post :new, :page => {:title => 'title with accents éèà'}
end

it 'should create a published page with a redirect' do
post(:new, 'page' => base_page)
assigns(:page).redirects.count.should == 1
Expand Down
21 changes: 11 additions & 10 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def only(*keys)

describe 'Given no pages' do
def valid_attributes
{ :name => 'name', :title => 'title', :body => 'body'}
{ :title => 'title', :body => 'body'}
end

before(:each) do
Expand All @@ -55,19 +55,11 @@ def valid_attributes
@page.should_not be_valid
end

it 'A page is valid with name, title and body' do
it 'A page is valid with a title and body' do
@page.attributes = valid_attributes
@page.should be_valid
end

it 'A page is invalid without a name' do
@page.attributes = valid_attributes.except(:name)
@page.should_not be_valid
@page.errors[:name].should == ["can't be blank"]
@page.name = 'somename'
@page.should be_valid
end

it 'A page is invalid without a title' do
@page.attributes = valid_attributes.except(:title)
@page.should_not be_valid
Expand All @@ -83,6 +75,15 @@ def valid_attributes
@page.body = 'somebody'
@page.should be_valid
end

it "should use sanitize title to set page name" do
@page.attributes = valid_attributes.except(:title)
@page.title = 'title with accents éèà'
@page.should be_valid
@page.save
@page.name.should == "title-with-accents-eea"
end

end

describe 'Given a valid page' do
Expand Down

0 comments on commit aae5924

Please sign in to comment.