Commit 5d7026de3dc80177724ed91a471f857ba9199c09

Authored by Antonio Terceiro
1 parent a7c0a5e1

Adding acceptance test infrastructure

features/step_definitions/noosfero_steps.rb
@@ -19,16 +19,37 @@ Given /^the following enterprises$/ do |table| @@ -19,16 +19,37 @@ Given /^the following enterprises$/ do |table|
19 end 19 end
20 end 20 end
21 21
22 -Given /^the following (articles|events)$/ do |content, table| 22 +Given /^the following blocks$/ do |table|
  23 + table.hashes.map{|item| item.dup}.each do |item|
  24 + klass = item.delete('type')
  25 + owner = Profile[item.delete('owner')]
  26 + box_id = owner.boxes.last.id
  27 + klass.constantize.create!(item.merge(:box_id => box_id))
  28 + end
  29 +end
  30 +
  31 +Given /^the following (articles|events|blogs)$/ do |content, table|
23 klass = { 32 klass = {
24 'articles' => TextileArticle, 33 'articles' => TextileArticle,
25 'events' => Event, 34 'events' => Event,
  35 + 'blogs' => Blog,
26 }[content] || raise("Don't know how to build %s" % content) 36 }[content] || raise("Don't know how to build %s" % content)
27 - table.hashes.each do |item|  
28 - data = item.dup  
29 - owner_identifier = data.delete("owner") 37 + table.hashes.map{|item| item.dup}.each do |item|
  38 + owner_identifier = item.delete("owner")
30 owner = Profile[owner_identifier] 39 owner = Profile[owner_identifier]
31 - TextileArticle.create!(data.merge(:profile => owner)) 40 + klass.create!(item.merge(:profile => owner))
  41 + end
  42 +end
  43 +
  44 +Given /^the following files$/ do |table|
  45 + table.hashes.each do |item|
  46 + owner = Profile[item[:owner]]
  47 + file = "/files/#{item[:file]}"
  48 + article = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime]))
  49 + if item[:homepage]
  50 + owner.home_page = article
  51 + owner.save!
  52 + end
32 end 53 end
33 end 54 end
34 55
@@ -40,3 +61,39 @@ Given /^the following products$/ do |table| @@ -40,3 +61,39 @@ Given /^the following products$/ do |table|
40 end 61 end
41 end 62 end
42 63
  64 +Given /^I am logged in as "(.+)"$/ do |username|
  65 + visit('/account/login')
  66 + fill_in("Username", :with => username)
  67 + fill_in("Password", :with => '123456')
  68 + click_button("Log in")
  69 +end
  70 +
  71 +Given /^I am logged in as admin$/ do
  72 + user = User.create!(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com')
  73 + e = Environment.default
  74 + e.add_admin(user.person)
  75 + visit('/account/login')
  76 + fill_in("Username", :with => user.login)
  77 + fill_in("Password", :with => '123456')
  78 + click_button("Log in")
  79 +end
  80 +
  81 +Given /^I am not logged in$/ do
  82 + visit('/account/logout')
  83 +end
  84 +
  85 +Given /^feature "(.+)" is enabled on environment$/ do |feature|
  86 + e = Environment.default
  87 + e.enable(feature)
  88 + e.save
  89 +end
  90 +
  91 +Given /^feature "(.+)" is disabled on environment$/ do |feature|
  92 + e = Environment.default
  93 + e.disable(feature)
  94 + e.save
  95 +end
  96 +
  97 +Given /^"(.+)" should be a member of "(.+)"$/ do |person,profile|
  98 + Profile.find_by_name(profile).members.should include(Person.find_by_name(person))
  99 +end
features/support/paths.rb
@@ -13,7 +13,16 @@ module NavigationHelpers @@ -13,7 +13,16 @@ module NavigationHelpers
13 13
14 when /^\// 14 when /^\//
15 page_name 15 page_name
16 - 16 +
  17 + when /^(.*)'s homepage$/
  18 + '/%s' % Profile.find_by_name($1).identifier
  19 +
  20 + when /^login page$/
  21 + '/account/login'
  22 +
  23 + when /^(.*)'s control panel$/
  24 + '/myprofile/%s' % Profile.find_by_name($1).identifier
  25 +
17 # Add more mappings here. 26 # Add more mappings here.
18 # Here is a more fancy example: 27 # Here is a more fancy example:
19 # 28 #