Skip to content

Commit

Permalink
Make cucumber tests work correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
peakpg committed May 20, 2011
1 parent 4d96e37 commit 32dedde
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 39 deletions.
27 changes: 14 additions & 13 deletions db/seeds.rb
Expand Up @@ -4,13 +4,13 @@
if %w[development test dev local].include?(Rails.env)
pwd = "cmsadmin"
else
pwd = (0..8).inject(""){|s,i| s << (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a).rand}
pwd = (0..8).inject("") { |s, i| s << (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a).rand }
end
User.current = create_user(:cmsadmin, :login => "cmsadmin", :first_name => "CMS", :last_name => "Administrator", :email => "cmsadmin@example.com", :password => pwd, :password_confirmation => pwd)

create_permission(:administrate, :name => "administrate", :full_name => "Administer CMS" , :description => "Allows users to administer the CMS, including adding users and groups.")
create_permission(:edit_content, :name => "edit_content", :full_name => "Edit Content" , :description => "Allows users to Add, Edit and Delete both Pages and Blocks. Can Save (but not Publish) and Assign them as well.")
create_permission(:publish_content, :name => "publish_content", :full_name => "Publish Content" , :description => "Allows users to Save and Publish, Hide and Archive both Pages and Blocks.")
create_permission(:administrate, :name => "administrate", :full_name => "Administer CMS", :description => "Allows users to administer the CMS, including adding users and groups.")
create_permission(:edit_content, :name => "edit_content", :full_name => "Edit Content", :description => "Allows users to Add, Edit and Delete both Pages and Blocks. Can Save (but not Publish) and Assign them as well.")
create_permission(:publish_content, :name => "publish_content", :full_name => "Publish Content", :description => "Allows users to Save and Publish, Hide and Archive both Pages and Blocks.")

create_group_type(:guest_group_type, :name => "Guest", :guest => true)
create_group_type(:registered_public_user, :name => "Registered Public User")
Expand All @@ -26,13 +26,13 @@
groups(:content_admin).permissions<<permissions(:administrate)
groups(:content_editor).permissions<<permissions(:edit_content)
groups(:content_editor).permissions<<permissions(:publish_content)
groups(:content_editor).permissions<<permissions(:publish_content)
create_site(:default, :name => "Default", :domain => "example.com")
create_section(:root, :name => "My Site", :path => "/", :root => true)
create_section(:system, :name => "system", :parent => sections(:root), :path => "/system", :hidden => true)
Group.all.each{|g| g.sections = Section.all }
Group.all.each { |g| g.sections = Section.all }
create_page(:home, :name => "Home", :path => "/", :section => sections(:root), :template_file_name => "default.html.erb", :cacheable => true)
create_page(:not_found, :name => "Page Not Found", :path => "/system/not_found", :section => sections(:system), :template_file_name => "default.html.erb", :publish_on_save => true, :hidden => true, :cacheable => true)
Expand All @@ -50,9 +50,10 @@
create_html_block(:server_error, :name => "Server Error", :content => "<p>The server encountered an unexpected condition that prevented it from fulfilling the request.</p>", :publish_on_save => true)
pages(:server_error).create_connector(html_blocks(:server_error), "main")
pages(:server_error).publish!
pages(:home).publish!
puts "*************************************************"
puts "* YOUR CMS username/password is: cmsadmin/#{pwd}"
puts "*************************************************"
pages(:home).publish!
unless Cms::DataLoader.silent_mode
puts "*************************************************"
puts "* YOUR CMS username/password is: cmsadmin/#{pwd}"
puts "*************************************************"
end
15 changes: 0 additions & 15 deletions features/content_pages.feature

This file was deleted.

14 changes: 14 additions & 0 deletions features/install_content.feature
@@ -0,0 +1,14 @@
Feature: Install blank site
In order to have a reasonable starting point
a web developer
wants a a blank site to be created with seed content.

Scenario: A homepage exists
Given I am on the homepage
Then I should see a page titled "Home"

Scenario: An error page exists
Given I am at /system/server_error
Then I should see a page titled "Server Error"


15 changes: 7 additions & 8 deletions features/step_definitions/content_pages_steps.rb
@@ -1,7 +1,7 @@
# ex: Then I should see a page titled "Home"
Then /^I should see a page titled "([^"]*)"$/ do |page_title|
page.has_css?("title", :text=>page_title)
page.has_content?(page_title)
page.should have_css("title", :text=>page_title)
page.should have_content(page_title)
end

Given /^I am logged in as a Content Editor$/ do
Expand Down Expand Up @@ -30,14 +30,13 @@
end

Given /^there is a homepage$/ do
page = Page.with_path("/").first
if page
@homepage = page
else
@homepage = Factory(:page, :path=>"/", :name=>"Home Page")
end
@homepage = Page.with_path("/").first
end

Then /^I should see Welcome, cmsadmin$/ do
page.has_content? 'Welcome, cmsadmin'
end

Given /^I am at (.+)/ do |path|
visit path
end
1 change: 1 addition & 0 deletions features/step_definitions/install_content_steps.rb
@@ -0,0 +1 @@
# Steps go here.
1 change: 1 addition & 0 deletions features/support/paths.rb
Expand Up @@ -11,6 +11,7 @@ def path_to(page_name)
when /the home\s?page/
'/'


# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
Expand Down
11 changes: 11 additions & 0 deletions features/support/test_setup.rb
@@ -0,0 +1,11 @@
require 'cms/data_loader'

AfterConfiguration do
DatabaseCleaner.clean
Cms::DataLoader.silent_mode = true
require File.join(File.dirname(__FILE__), '../../db/seeds.rb')
end


require 'factory_girl'
require File.join(File.dirname(__FILE__), '../../test/factories.rb')
5 changes: 4 additions & 1 deletion lib/cms/data_loader.rb
@@ -1,5 +1,8 @@
module Cms
module DataLoader

mattr_accessor :silent_mode

def method_missing(method_name, *args)
if md = method_name.to_s.match(/^create_(.+)$/)
begin
Expand All @@ -17,7 +20,7 @@ def method_missing(method_name, *args)
end
end
def create(model_name, record_name, data={})
puts "-- create_#{model_name}(:#{record_name})"
puts "-- create_#{model_name}(:#{record_name})" unless Cms::DataLoader.silent_mode
@data ||= {}
@data[model_name.pluralize.to_sym] ||= {}
model = model_name.classify.constantize.new(data)
Expand Down
12 changes: 11 additions & 1 deletion test/factories.rb
Expand Up @@ -102,12 +102,22 @@
m.sequence(:name) {|n| "TestPermission#{n}" }
end

def create_or_find_root_section
root = Section.root.first
unless root
root = Section.create!(:name=>"Root", :root=>true, :path=>"/")
end
root
end

Factory.define :section do |m|
m.name "Test"
m.path "/"
m.parent { Section.root.first }
m.parent { create_or_find_root_section }
end



Factory.define :site do |m|
m.sequence(:name) {|n| "Test #{n}"}
m.domain {|a| "#{a.name.gsub(/\s/,"_").downcase}.com" }
Expand Down
7 changes: 6 additions & 1 deletion todo_list.txt
Expand Up @@ -3,7 +3,12 @@ Status

BrowserCMS 3.3.0 is complete.

Gems to Publish (once its live)
Cucumber Recommendations
* Avoid using selectors unless it really matters.
* Express intent in scenarios
* Can group multiple steps into a single step

Gems to Publish (once its live)
============
bcms_fckeditor - 1.1.0 is pushed to github. Gem needs to be pushed as well. Need to test file upload (browser.xml) from within the browser
bcms_news - 1.2 pushed to github. Gem not released yet. (Has bugs)
Expand Down

0 comments on commit 32dedde

Please sign in to comment.