From 5d7026de3dc80177724ed91a471f857ba9199c09 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Wed, 11 Nov 2009 14:12:03 -0300 Subject: [PATCH] Adding acceptance test infrastructure --- features/step_definitions/noosfero_steps.rb | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- features/support/paths.rb | 11 ++++++++++- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 48d4a65..61d1387 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -19,16 +19,37 @@ Given /^the following enterprises$/ do |table| end end -Given /^the following (articles|events)$/ do |content, table| +Given /^the following blocks$/ do |table| + table.hashes.map{|item| item.dup}.each do |item| + klass = item.delete('type') + owner = Profile[item.delete('owner')] + box_id = owner.boxes.last.id + klass.constantize.create!(item.merge(:box_id => box_id)) + end +end + +Given /^the following (articles|events|blogs)$/ do |content, table| klass = { 'articles' => TextileArticle, 'events' => Event, + 'blogs' => Blog, }[content] || raise("Don't know how to build %s" % content) - table.hashes.each do |item| - data = item.dup - owner_identifier = data.delete("owner") + table.hashes.map{|item| item.dup}.each do |item| + owner_identifier = item.delete("owner") owner = Profile[owner_identifier] - TextileArticle.create!(data.merge(:profile => owner)) + klass.create!(item.merge(:profile => owner)) + end +end + +Given /^the following files$/ do |table| + table.hashes.each do |item| + owner = Profile[item[:owner]] + file = "/files/#{item[:file]}" + article = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) + if item[:homepage] + owner.home_page = article + owner.save! + end end end @@ -40,3 +61,39 @@ Given /^the following products$/ do |table| end end +Given /^I am logged in as "(.+)"$/ do |username| + visit('/account/login') + fill_in("Username", :with => username) + fill_in("Password", :with => '123456') + click_button("Log in") +end + +Given /^I am logged in as admin$/ do + user = User.create!(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') + e = Environment.default + e.add_admin(user.person) + visit('/account/login') + fill_in("Username", :with => user.login) + fill_in("Password", :with => '123456') + click_button("Log in") +end + +Given /^I am not logged in$/ do + visit('/account/logout') +end + +Given /^feature "(.+)" is enabled on environment$/ do |feature| + e = Environment.default + e.enable(feature) + e.save +end + +Given /^feature "(.+)" is disabled on environment$/ do |feature| + e = Environment.default + e.disable(feature) + e.save +end + +Given /^"(.+)" should be a member of "(.+)"$/ do |person,profile| + Profile.find_by_name(profile).members.should include(Person.find_by_name(person)) +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 84c52da..f95d51d 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -13,7 +13,16 @@ module NavigationHelpers when /^\// page_name - + + when /^(.*)'s homepage$/ + '/%s' % Profile.find_by_name($1).identifier + + when /^login page$/ + '/account/login' + + when /^(.*)'s control panel$/ + '/myprofile/%s' % Profile.find_by_name($1).identifier + # Add more mappings here. # Here is a more fancy example: # -- libgit2 0.21.2