From e1da1211043b549714804cd3bffc05b680e6fea9 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 14 Feb 2014 18:40:31 -0300 Subject: [PATCH] rails3: fix some cucumber tests --- app/controllers/public/content_viewer_controller.rb | 2 +- app/helpers/application_helper.rb | 4 ++++ app/models/blog.rb | 2 +- app/models/domain.rb | 2 +- app/models/forum.rb | 2 +- app/models/organization.rb | 2 +- app/models/product_categories_block.rb | 2 +- app/models/production_cost.rb | 2 +- app/models/profile.rb | 2 +- app/models/validation_info.rb | 2 +- features/plugins.feature | 4 ++-- features/step_definitions/create_community_steps.rb | 10 +++++----- features/step_definitions/http_caching_steps.rb | 2 +- features/step_definitions/noosfero_steps.rb | 14 +++++++------- features/step_definitions/web_steps.rb | 3 ++- features/support/fixture_path.rb | 5 +++++ 16 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 features/support/fixture_path.rb diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 01c4b44..a93cece 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -118,7 +118,7 @@ class ContentViewerController < ApplicationController end def article_versions - path = params[:page].join('/') + path = params[:page] @page = profile.articles.find_by_path(path) return unless allow_access_to_page(path) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cd2784f..0d28634 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -764,6 +764,10 @@ module ApplicationHelper (field_helpers - %w(hidden_field)).each do |selector| src = <<-END_SRC def #{selector}(field, *args, &proc) + begin + object ||= @template.instance_variable_get("@"+object_name.to_s) + rescue + end text = object.class.respond_to?(:human_attribute_name) && object.class.human_attribute_name(field.to_s) || field.to_s.humanize NoosferoFormBuilder::output_field(text, super) end diff --git a/app/models/blog.rb b/app/models/blog.rb index 2b81a13..ea56fd0 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -55,7 +55,7 @@ class Blog < Folder if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i self.external_feed.attributes = self.external_feed_data else - self.build_external_feed(self.external_feed_data) + self.build_external_feed(self.external_feed_data, :without_protection => true) end self.external_feed.valid? self.external_feed.errors.delete(:blog_id) # dont validate here relation: external_feed <-> blog diff --git a/app/models/domain.rb b/app/models/domain.rb index 03788a7..340dc0c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -2,7 +2,7 @@ require 'noosfero/multi_tenancy' class Domain < ActiveRecord::Base - attr_accessible :name + attr_accessible :name, :owner # relationships ############### diff --git a/app/models/forum.rb b/app/models/forum.rb index f432acd..8c7f5c0 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -3,7 +3,7 @@ class Forum < Folder acts_as_having_posts :order => 'updated_at DESC' include PostsLimit - attr_accessible :has_terms_of_use + attr_accessible :has_terms_of_use, :terms_of_use settings_items :terms_of_use, :type => :string, :default => "" settings_items :has_terms_of_use, :type => :boolean, :default => false diff --git a/app/models/organization.rb b/app/models/organization.rb index 87d94ab..eac49b5 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,7 +1,7 @@ # Represents any organization of the system class Organization < Profile - attr_accessible :moderated_articles, :foundation_year, :contact_person, :acronym, :legal_form, :economic_activity, :management_information, :cnpj, :display_name + attr_accessible :moderated_articles, :foundation_year, :contact_person, :acronym, :legal_form, :economic_activity, :management_information, :cnpj, :display_name, :enable_contact_us SEARCH_FILTERS += %w[ more_popular diff --git a/app/models/product_categories_block.rb b/app/models/product_categories_block.rb index 9f0fd02..3dff0f6 100644 --- a/app/models/product_categories_block.rb +++ b/app/models/product_categories_block.rb @@ -15,7 +15,7 @@ class ProductCategoriesBlock < Block def content(args={}) profile = owner - lambda do + proc do if @categories.nil? or @categories.length == 0 categories = ProductCategory.on_level().order(:name) if @categories and @categories.length == 0 diff --git a/app/models/production_cost.rb b/app/models/production_cost.rb index 0962776..f0df85b 100644 --- a/app/models/production_cost.rb +++ b/app/models/production_cost.rb @@ -1,6 +1,6 @@ class ProductionCost < ActiveRecord::Base - attr_accessible :name + attr_accessible :name, :owner belongs_to :owner, :polymorphic => true validates_presence_of :owner diff --git a/app/models/profile.rb b/app/models/profile.rb index 4e90cf1..9feb674 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,7 +3,7 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email + attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n # use for internationalizable human type names in search facets # reimplement on subclasses diff --git a/app/models/validation_info.rb b/app/models/validation_info.rb index 2683531..7945d7c 100644 --- a/app/models/validation_info.rb +++ b/app/models/validation_info.rb @@ -1,6 +1,6 @@ class ValidationInfo < ActiveRecord::Base - attr_accessible :validation_methodology, :restrictions + attr_accessible :validation_methodology, :restrictions, :organization validates_presence_of :validation_methodology diff --git a/features/plugins.feature b/features/plugins.feature index 902224c..0adb78c 100644 --- a/features/plugins.feature +++ b/features/plugins.feature @@ -18,8 +18,8 @@ Feature: plugins | TestPlugin | And the following events of TestPlugin | event | body | - | control_panel_buttons | lambda { {:title => 'Test plugin button', :icon => '', :url => ''} } | - | profile_tabs | lambda { {:title => 'Test plugin tab', :id => 'test_plugin', :content => lambda {'Test plugin random content'} } } | + | control_panel_buttons | proc { {:title => 'Test plugin button', :icon => '', :url => ''} } | + | profile_tabs | proc { {:title => 'Test plugin tab', :id => 'test_plugin', :content => proc {'Test plugin random content'} } } | Scenario: a user must see the plugin\'s button in the control panel if the plugin is enabled Given plugin Test is enabled on environment diff --git a/features/step_definitions/create_community_steps.rb b/features/step_definitions/create_community_steps.rb index 8ce49a4..2732962 100644 --- a/features/step_definitions/create_community_steps.rb +++ b/features/step_definitions/create_community_steps.rb @@ -1,7 +1,7 @@ include DatesHelper Given /^I create community "(.+)"$/ do |community| - Given %{I go to admin_user's control panel} + step %{I go to admin_user's control panel} click_link('Manage my groups') click_link('Create a new community') fill_in("Name", :with => community) @@ -10,18 +10,18 @@ end Given /^I approve community "(.+)"$/ do |community| task = CreateCommunity.all.select {|c| c.name == community}.first - Given %{I go to admin_user's control panel} + step %{I go to admin_user's control panel} click_link('Process requests') choose("decision-finish-#{task.id}") - click_button('Apply!') + first(:button, 'Apply!').click end Given /^I reject community "(.+)"$/ do |community| task = CreateCommunity.all.select {|c| c.name == community}.first - Given %{I go to admin_user's control panel} + step %{I go to admin_user's control panel} click_link('Process requests') choose("decision-cancel-#{task.id}") - click_button('Apply!') + first(:button, 'Apply!').click end Then /^I should see "([^\"]*)"'s creation date$/ do |community| diff --git a/features/step_definitions/http_caching_steps.rb b/features/step_definitions/http_caching_steps.rb index 66a94d2..8f45273 100644 --- a/features/step_definitions/http_caching_steps.rb +++ b/features/step_definitions/http_caching_steps.rb @@ -13,7 +13,7 @@ Then /^there must be no cache at all$/ do end Then 'there must be no cookies' do - cookies.should == {} + cookies.to_hash.should == {} end Then /^there must be a cookie "(.+)"$/ do |cookie_name| diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index b1185e7..db55b62 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -36,7 +36,7 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do | end if domain d = Domain.new :name => domain, :owner => organization - d.save(false) + d.save(:validate => false) end if city c = City.find_by_name city @@ -79,7 +79,7 @@ Given /^the folllowing "([^\"]*)" from "([^\"]*)"$/ do |kind, plugin, table| end if domain d = Domain.new :name => domain, :owner => organization - d.save(false) + d.save(:validate => false) end end end @@ -203,7 +203,7 @@ Given /^the following products?$/ do |table| qualifier = Qualifier.find_by_name(data.delete("qualifier")) data.merge!(:qualifiers => [qualifier]) end - product = Product.create!(data) + product = Product.create!(data, :without_protection => true) end end @@ -216,7 +216,7 @@ Given /^the following inputs?$/ do |table| solidary = data.delete("solidary") input = Input.create!(data.merge(:product => product, :product_category => category, :unit => unit, :is_from_solidarity_economy => solidary), :without_protection => true) - input.update_attributes!(:position => data['position']) + input.update_attribute(:position, data['position']) end end @@ -224,7 +224,7 @@ Given /^the following states$/ do |table| table.hashes.each do |item| data = item.dup if validator = Enterprise.find_by_name(data.delete("validator_name")) - State.create!(data.merge(:environment => Environment.default, :validators => [validator])) + State.create!(data.merge(:environment => Environment.default, :validators => [validator]), :without_protection => true) else r = State.create!(data.merge(:environment => Environment.default)) end @@ -421,7 +421,7 @@ Given /^enterprise "([^\"]*)" is disabled$/ do |enterprise_name| end Then /^the page title should be "(.*)"$/ do |text| - Then %{I should see "#{text}" within "title"} + step %{I should see "#{text}" within "title"} end Then /^The page should contain "(.*)"$/ do |selector| @@ -534,7 +534,7 @@ end Given /^the environment domain is "([^\"]*)"$/ do |domain| d = Domain.new :name => domain, :owner => Environment.default - d.save(false) + d.save(:validate => false) end When /^([^\']*)'s account is activated$/ do |person| diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 70108e3..669f2fe 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -11,7 +11,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "pat module WithinHelpers def with_scope(locator) - locator ? first(locator) { yield } : yield + locator = locator ? first(locator) : locator + locator ? within(locator) { yield } : yield end end World(WithinHelpers) diff --git a/features/support/fixture_path.rb b/features/support/fixture_path.rb new file mode 100644 index 0000000..b2a16f8 --- /dev/null +++ b/features/support/fixture_path.rb @@ -0,0 +1,5 @@ +module FixturePathHelper + def (ActionDispatch::Integration::Session).fixture_path + ActionController::TestCase.fixture_path + end +end -- libgit2 0.21.2