change load behaviour in a better engine way and add more tests

This commit is contained in:
2012-12-14 18:19:04 +01:00
parent 0d6aeea49a
commit 90fd490909
13 changed files with 146 additions and 61 deletions
+45
View File
@@ -0,0 +1,45 @@
require 'acceptance/acceptance_helper'
feature 'Pages index', %q{
In order have pages
As a user
I want to see pages
} do
scenario 'visit root' do
visit '/cmtool'
page.current_path.should == '/users/sign_in'
end
context 'with logged in user' do
background do
create_user 'test@example.com'
login_as 'test@example.com'
end
context 'without pages' do
scenario 'list pages as root' do
visit '/cmtool'
page.should have_link 'New Page'
end
end
context 'with pages' do
background do
@nl1 = create :page, name: 'nl1', locale: 'nl'
@nl11 = create :page, name: 'nl11', locale: 'nl', parent_id: @nl1.id
@nl111 = create :page, name: 'nl111', locale: 'nl', parent_id: @nl11.id
@nl12 = create :page, name: 'nl12', locale: 'nl', parent_id: @nl1.id
@en1 = create :page, name: 'en1', locale: 'en'
end
scenario 'see both languages' do
visit '/cmtool'
page.should have_link 'nl1'
page.should have_link '- nl11'
page.should have_link '- - nl111'
page.should have_link '- nl12'
page.should have_link 'en1'
end
end
end
end
+14 -1
View File
@@ -1,6 +1,19 @@
module HelperMethods
# Put helper methods you need to be available in all acceptance specs here.
def create_user(email, password='secret')
@user = User.find_by_email(email) || FactoryGirl.create(:user, email: email, password: password)
end
def login_as(email)
visit "/users/sign_in"
fill_in "user_email", with: email
fill_in "user_password", with: "secret"
submit_form
end
def submit_form
find("[type=submit]").click
end
end
RSpec.configuration.include HelperMethods, :type => :acceptance
RSpec.configuration.include HelperMethods, :type => :acceptance
+10
View File
@@ -63,5 +63,15 @@ describe Cmtool::Menu do
second_last.should be_a Cmtool::Menu::ResourceLink
second_last.resource.should == Page
end
it "should fall back to normal behaviour when no menu item specified is found" do
Cmtool::Menu.reset!
Cmtool::Menu.register do
append_to :publications do
resource_link Cmtool::Directory
end
end
Cmtool::Menu.items.size.should == 1
end
end
end
+6
View File
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :page, class: Page do
sequence(:name){|i| "page#{i}"}
locale 'en'
end
end
+21
View File
@@ -0,0 +1,21 @@
require 'spec_helper'
describe Page do
before :each do
@nl1 = create :page, name: 'nl1', locale: 'nl'
@nl11 = create :page, name: 'nl11', locale: 'nl', parent_id: @nl1.id
@nl111 = create :page, name: 'nl111', locale: 'nl', parent_id: @nl11.id
@nl12 = create :page, name: 'nl12', locale: 'nl', parent_id: @nl1.id
@en1 = create :page, name: 'en1', locale: 'en'
end
describe :ancestry do
it "should not be valid when the parent has a different locale then the page itself" do
@nl12.parent_id = @en1.id
@nl12.should_not be_valid
@nl12.error_on(:locale).should_not be_empty
end
end
end
+1 -14
View File
@@ -15,7 +15,7 @@ Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f
I18n.locale = :en
Devise.stretches = 1
Capybara.default_driver = :selenium
#Capybara.default_driver = :selenium
RSpec.configure do |config|
config.mock_with :rspec
config.include FactoryGirl::Syntax::Methods
@@ -42,19 +42,6 @@ RSpec.configure do |config|
config.before :all do
end
config.before :each, type: :request do
#Capybara.current_driver = :selenium
sign_in_user_through_request
end
config.after :each, type: :request do
visit "/users/sign_out"
end
def sign_in_user_through_request
visit "/users/sign_in"
fill_in 'user[email]', with: @user.email
fill_in 'user[password]', with: @user.password
click_on 'Sign in'
end
def create_pages_tree
root1 = Page.create(name: 'root1', locale: 'en')