[noosfero/noosfero][rails4] 7 commits: rails4: replace includes with joins to fix query error
Bráulio Bhavamitra
gitlab at gitlab.com
Sat Apr 4 23:27:05 BRT 2015
Bráulio Bhavamitra pushed to rails4 at Noosfero / noosfero
Commits:
cb73010a by Braulio Bhavamitra at 2015-04-03T18:33:37Z
rails4: replace includes with joins to fix query error
- - - - -
058e5fc6 by Braulio Bhavamitra at 2015-04-03T18:54:06Z
rails4: fix unitinialized constant Test
- - - - -
cf59ca79 by Braulio Bhavamitra at 2015-04-03T18:54:45Z
rails4: assert_block was deprecated
- - - - -
d3f09b60 by Braulio Bhavamitra at 2015-04-04T23:19:46Z
rails4.2: migrate type casting as acts_as_having_settings
- - - - -
dccd6a24 by Braulio Bhavamitra at 2015-04-04T23:21:21Z
rails4: from Task.find_by_code to scope
- - - - -
d9366b27 by Braulio Bhavamitra at 2015-04-04T23:21:44Z
rails4: fix tests init
- - - - -
11b47ca7 by Braulio Bhavamitra at 2015-04-04T23:23:17Z
rails4: remove deprecated application controller file
- - - - -
17 changed files:
- − app/controllers/application.rb
- app/controllers/public/account_controller.rb
- app/models/blog_archives_block.rb
- app/models/link_list_block.rb
- app/models/person.rb
- app/models/products_block.rb
- app/models/task.rb
- config/application.rb
- lib/acts_as_having_settings.rb
- − lib/noosfero/test.rb
- plugins/statistics/lib/statistics_block.rb
- test/factories.rb
- test/functional/account_controller_test.rb
- test/test_helper.rb
- test/unit/acts_as_having_settings_test.rb
- test/unit/catalog_helper_test.rb
- test/unit/task_test.rb
Changes:
=====================================
app/controllers/application.rb deleted
=====================================
--- a/app/controllers/application.rb
+++ /dev/null
@@ -1 +0,0 @@
-require 'application_controller'
=====================================
app/controllers/public/account_controller.rb
=====================================
--- a/app/controllers/public/account_controller.rb
+++ b/app/controllers/public/account_controller.rb
@@ -16,7 +16,7 @@ class AccountController < ApplicationController
def activate
@user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code]
if @user
- unless @user.environment.enabled?('admin_must_approve_new_users')
+ unless @user.environment.enabled?('admin_must_approve_new_users')
if @user.activate
@message = _("Your account has been activated, now you can log in!")
check_redirection
@@ -30,7 +30,7 @@ class AccountController < ApplicationController
@user.activation_code = nil
@user.save!
redirect_to :controller => :home
- end
+ end
end
else
session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?")
@@ -113,7 +113,7 @@ class AccountController < ApplicationController
@user.signup!
owner_role = Role.find_by_name('owner')
@user.person.affiliate(@user.person, [owner_role]) if owner_role
- invitation = Task.find_by_code(@invitation_code)
+ invitation = Task.from_code @invitation_code
if invitation
invitation.update_attributes!({:friend => @user.person})
invitation.finish
@@ -205,7 +205,7 @@ class AccountController < ApplicationController
#
# Posts back.
def new_password
- @change_password = ChangePassword.find_by_code(params[:code])
+ @change_password = ChangePassword.from_code params[:code]
unless @change_password
render :action => 'invalid_change_password_code', :status => 403
@@ -394,7 +394,7 @@ class AccountController < ApplicationController
end
def load_enterprise_activation
- @enterprise_activation ||= EnterpriseActivation.find_by_code(params[:enterprise_code])
+ @enterprise_activation ||= EnterpriseActivation.from_code params[:enterprise_code]
end
def load_enterprise
=====================================
app/models/blog_archives_block.rb
=====================================
--- a/app/models/blog_archives_block.rb
+++ b/app/models/blog_archives_block.rb
@@ -15,7 +15,7 @@ class BlogArchivesBlock < Block
_('Blog posts')
end
- settings_items :blog_id, Integer
+ settings_items :blog_id, type: Integer
def blog
blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog
=====================================
app/models/link_list_block.rb
=====================================
--- a/app/models/link_list_block.rb
+++ b/app/models/link_list_block.rb
@@ -41,7 +41,7 @@ class LinkListBlock < Block
[N_('New window'), '_new'],
]
- settings_items :links, Array, :default => []
+ settings_items :links, type: Array, :default => []
before_save do |block|
block.links = block.links.delete_if {|i| i[:name].blank? and i[:address].blank?}
=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -71,7 +71,7 @@ class Person < Profile
has_many :friends, :class_name => 'Person', :through => :friendships
scope :online, -> {
- includes(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes)
+ joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes)
}
has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy
=====================================
app/models/products_block.rb
=====================================
--- a/app/models/products_block.rb
+++ b/app/models/products_block.rb
@@ -39,7 +39,7 @@ class ProductsBlock < Block
link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index'))
end
- settings_items :product_ids, Array
+ settings_items :product_ids, type: Array
def product_ids=(array)
self.settings[:product_ids] = array
if self.settings[:product_ids]
=====================================
app/models/task.rb
=====================================
--- a/app/models/task.rb
+++ b/app/models/task.rb
@@ -48,7 +48,7 @@ class Task < ActiveRecord::Base
before_validation(:on => :create) do |task|
if task.code.nil?
task.code = Task.generate_code(task.code_length)
- while (Task.find_by_code(task.code))
+ while Task.from_code(task.code).first
task.code = Task.generate_code(task.code_length)
end
end
@@ -293,6 +293,12 @@ class Task < ActiveRecord::Base
end
end
+ # finds a task by its (generated) code. Only returns a task with the
+ # specified code AND with status = Task::Status::ACTIVE.
+ #
+ # Can be used in subclasses to find only their instances.
+ scope :from_code, -> (code) { where code: code, status: Task::Status::ACTIVE }
+
class << self
# generates a random code string consisting of length characters (or 36 by
@@ -306,14 +312,6 @@ class Task < ActiveRecord::Base
code
end
- # finds a task by its (generated) code. Only returns a task with the
- # specified code AND with status = Task::Status::ACTIVE.
- #
- # Can be used in subclasses to find only their instances.
- def find_by_code(code)
- self.where(code: code, status: Task::Status::ACTIVE)
- end
-
def per_page
15
end
=====================================
config/application.rb
=====================================
--- a/config/application.rb
+++ b/config/application.rb
@@ -29,7 +29,7 @@ module Noosfero
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W( #{Rails.root.join('app', 'sweepers')} )
- config.autoload_paths += Dir["#{config.root}/lib/**/"]
+ config.autoload_paths += Dir["#{config.root}/lib"]
config.autoload_paths += Dir["#{config.root}/app/controllers/**/"]
config.autoload_paths += %W( #{Rails.root.join('test', 'mocks', Rails.env)} )
=====================================
lib/acts_as_having_settings.rb
=====================================
--- a/lib/acts_as_having_settings.rb
+++ b/lib/acts_as_having_settings.rb
@@ -1,64 +1,81 @@
+# declare missing types
+module ActiveRecord
+ module Type
+ class Symbol < Value
+ def cast_value value
+ value.to_sym
+ end
+ end
+ class Array < Value
+ def cast_value value
+ Array(value)
+ end
+ end
+ class Hash < Value
+ def cast_value value
+ Hash[value]
+ end
+ end
+ end
+end
+
module ActsAsHavingSettings
module ClassMethods
+
def acts_as_having_settings(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
-
- settings_field = options[:field] || 'settings'
+ field = (options[:field] || :settings).to_sym
- class_eval <<-CODE
- serialize :#{settings_field}, Hash
- def self.settings_field
- #{settings_field.inspect}
- end
- def #{settings_field}
- self[:#{settings_field}] ||= Hash.new
+ serialize field, Hash
+ class_attribute :settings_field
+ self.settings_field = field
+
+ class_eval do
+ def settings_field
+ self[self.class.settings_field] ||= Hash.new
end
- def setting_changed?(setting_field)
+ def setting_changed? setting_field
setting_field = setting_field.to_sym
- changed_settings = self.changes['#{settings_field}']
+ changed_settings = self.changes[self.class.settings_field]
return false if changed_settings.nil?
old_setting_value = changed_settings.first.nil? ? nil : changed_settings.first[setting_field]
new_setting_value = changed_settings.last[setting_field]
old_setting_value != new_setting_value
end
+ end
- before_save :symbolize_settings_keys
- private
- def symbolize_settings_keys
- self[:#{settings_field}] && self[:#{settings_field}].symbolize_keys!
- end
- CODE
- settings_items(*args)
+ settings_items *args
end
def settings_items(*names)
options = names.last.is_a?(Hash) ? names.pop : {}
- default = (!options[:default].nil?) ? options[:default].inspect : "val"
- data_type = options[:type] || :string
+ default = if !options[:default].nil? then options[:default] else nil end
+ data_type = options[:type]
+ data_type = if data_type.present? then data_type.to_s.camelize.to_sym else :String end
+ data_type = ActiveRecord::Type.const_get(data_type).new
names.each do |setting|
- class_eval <<-CODE
- def #{setting}
- val = send(self.class.settings_field)[:#{setting}]
- val.nil? ? (#{default}.is_a?(String) ? gettext(#{default}) : #{default}) : val
- end
- def #{setting}=(value)
- h = send(self.class.settings_field).clone
- h[:#{setting}] = self.class.acts_as_having_settings_type_cast(value, #{data_type.inspect})
- send(self.class.settings_field.to_s + '=', h)
- end
- CODE
+ # symbolize key
+ setting = setting.to_sym
+
+ define_method setting do
+ h = send self.class.settings_field
+ val = h[setting]
+ if val.nil? then (if default.is_a? String then gettext default else default end) else val end
+ end
+ define_method "#{setting}=" do |value|
+ h = send self.class.settings_field
+ h[setting] = self.class.acts_as_having_settings_type_cast value, data_type
+ end
end
end
- def acts_as_having_settings_type_cast(value, type)
- # FIXME creating a new instance at every call, will the garbage collector
- # be able to cope with it?
- ActiveRecord::ConnectionAdapters::Column.new(:dummy, nil, type.to_s).type_cast(value)
+ def acts_as_having_settings_type_cast value, type
+ type.send :cast_value, value
end
end
=====================================
lib/noosfero/test.rb deleted
=====================================
--- a/lib/noosfero/test.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module Noosfero::Test
-
- def get(path, parameters = nil, headers = nil)
- super(path, (parameters ? self.class.extra_parameters.merge(parameters) : self.class.extra_parameters) , headers)
- end
-
- def post(path, parameters = nil, headers = nil)
- super(path, (parameters ? self.class.extra_parameters.merge(parameters) : self.class.extra_parameters), headers)
- end
-
- module ClassMethods
- def noosfero_test(parameters)
- instance_variable_set('@noosfero_test_extra_parameters', parameters)
- def extra_parameters
- @noosfero_test_extra_parameters
- end
- include Noosfero::Test
- end
- end
-
-end
-
-Test::Unit::TestCase.send(:extend, Noosfero::Test::ClassMethods)
=====================================
plugins/statistics/lib/statistics_block.rb
=====================================
--- a/plugins/statistics/lib/statistics_block.rb
+++ b/plugins/statistics/lib/statistics_block.rb
@@ -8,7 +8,7 @@ class StatisticsBlock < Block
settings_items :tag_counter, :default => true
settings_items :comment_counter, :default => true
settings_items :hit_counter, :default => false
- settings_items :templates_ids_counter, Hash, :default => {}
+ settings_items :templates_ids_counter, type: Hash, default: {}
attr_accessible :comment_counter, :community_counter, :user_counter, :enterprise_counter, :product_counter, :category_counter, :tag_counter, :hit_counter, :templates_ids_counter
=====================================
test/factories.rb
=====================================
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -140,7 +140,7 @@ module Noosfero::Factory
end
def fast_update(obj, data)
- obj.class.connection.execute('update %s set %s where id = %d' % [obj.class.table_name, ActiveRecord::Base.send(:sanitize_sql_for_assignment, data), obj.id])
+ obj.class.connection.execute('update %s set %s where id = %d' % [obj.class.table_name, obj.class.send(:sanitize_sql_for_assignment, data), obj.id])
end
def give_permission(user, permission, target)
=====================================
test/functional/account_controller_test.rb
=====================================
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -241,7 +241,7 @@ class AccountControllerTest < ActionController::TestCase
should 'provide interface for entering new password' do
change = ChangePassword.new
- ChangePassword.expects(:find_by_code).with('osidufgiashfkjsadfhkj99999').returns(change)
+ ChangePassword.expects(:from_code).with('osidufgiashfkjsadfhkj99999').returns(change)
person = mock
person.stubs(:identifier).returns('joe')
person.stubs(:name).returns('Joe')
@@ -253,7 +253,7 @@ class AccountControllerTest < ActionController::TestCase
should 'actually change password after entering new password' do
change = ChangePassword.new
- ChangePassword.expects(:find_by_code).with('osidufgiashfkjsadfhkj99999').returns(change)
+ ChangePassword.expects(:from_code).with('osidufgiashfkjsadfhkj99999').returns(change)
requestor = mock
requestor.stubs(:identifier).returns('joe')
@@ -323,7 +323,7 @@ class AccountControllerTest < ActionController::TestCase
person = create_user('mylogin').person
login_as(person.identifier)
- EnterpriseActivation.expects(:find_by_code).with('some_invalid_code').returns(nil).at_least_once
+ EnterpriseActivation.expects(:from_code).with('some_invalid_code').returns(nil).at_least_once
get :activation_question, :enterprise_code => 'some_invalid_code'
@@ -338,7 +338,7 @@ class AccountControllerTest < ActionController::TestCase
ent.update_attribute(:cnpj, '0'*14)
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -353,7 +353,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -368,7 +368,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -384,7 +384,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -400,7 +400,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -417,7 +417,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -433,7 +433,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :activation_question, :enterprise_code => '0123456789'
@@ -446,7 +446,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).never
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).never
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).never
post :accept_terms, :enterprise_code => '0123456789', :answer => '1998'
@@ -462,7 +462,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
post :accept_terms, :enterprise_code => '0123456789', :answer => '1997'
@@ -484,7 +484,7 @@ class AccountControllerTest < ActionController::TestCase
ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent', :enabled => false)
ent.update_attribute(:foundation_year, 1998)
task = EnterpriseActivation.create!(:enterprise => ent)
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
post :accept_terms, :enterprise_code => '0123456789', :answer => '1998'
@@ -503,7 +503,7 @@ class AccountControllerTest < ActionController::TestCase
task = mock
task.expects(:enterprise).returns(ent).at_least_once
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
get :accept_terms, :enterprise_code => '0123456789', :answer => 1998
@@ -517,7 +517,7 @@ class AccountControllerTest < ActionController::TestCase
ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent', :enabled => false)
ent.update_attribute(:foundation_year, 1998)
task = EnterpriseActivation.create!(:enterprise => ent)
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).never
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).never
post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true
@@ -531,7 +531,7 @@ class AccountControllerTest < ActionController::TestCase
login_as(p.identifier)
task = EnterpriseActivation.create!(:enterprise => ent)
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => false
ent.reload
@@ -547,7 +547,7 @@ class AccountControllerTest < ActionController::TestCase
login_as(p.identifier)
task = EnterpriseActivation.create!(:enterprise => ent)
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true
ent.reload
@@ -566,7 +566,7 @@ class AccountControllerTest < ActionController::TestCase
ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent', :enabled => false)
ent.update_attribute(:foundation_year, 1998)
task = EnterpriseActivation.create!(:enterprise => ent)
- EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
+ EnterpriseActivation.expects(:from_code).with('0123456789').returns(task).at_least_once
post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true
=====================================
test/test_helper.rb
=====================================
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,14 +1,14 @@
ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+require_relative "../config/environment"
require 'rails/test_help'
require 'mocha'
+require 'mocha/mini_test'
-require 'noosfero/test'
require 'authenticated_test_helper'
-require File.dirname(__FILE__) + '/factories'
-require File.dirname(__FILE__) + '/noosfero_doc_test'
-require File.dirname(__FILE__) + '/action_tracker_test_helper'
+require_relative 'factories'
+require_relative 'noosfero_doc_test'
+require_relative 'action_tracker_test_helper'
FileUtils.rm_rf(Rails.root.join('index', 'test'))
@@ -76,7 +76,28 @@ class ActiveSupport::TestCase
end
- alias :ok :assert_block
+ def self.noosfero_test parameters
+ instance_variable_set('@noosfero_test_extra_parameters', parameters)
+ def extra_parameters
+ @noosfero_test_extra_parameters
+ end
+ end
+
+ def get(path, parameters = nil, headers = nil)
+ super(path, (parameters ? self.class.extra_parameters.merge(parameters) : self.class.extra_parameters) , headers)
+ end
+
+ def post(path, parameters = nil, headers = nil)
+ super(path, (parameters ? self.class.extra_parameters.merge(parameters) : self.class.extra_parameters), headers)
+ end
+
+ # deprecated on minitest
+ def assert_block message=nil
+ assert message || 'yield' do
+ yield
+ end
+ end
+ alias_method :ok, :assert_block
def assert_equivalent(enum1, enum2)
assert( ((enum1 - enum2) == []) && ((enum2 - enum1) == []), "<#{enum1.inspect}> expected to be equivalent to <#{enum2.inspect}>")
=====================================
test/unit/acts_as_having_settings_test.rb
=====================================
--- a/test/unit/acts_as_having_settings_test.rb
+++ b/test/unit/acts_as_having_settings_test.rb
@@ -2,11 +2,12 @@ require_relative "../test_helper"
class ActsAsHavingSettingsTest < ActiveSupport::TestCase
- # using Block class as a sample user of the module
+ # using Block class as a sample user of the module
class TestClass < Block
- settings_items :flag, :type => :boolean
- settings_items :flag_disabled_by_default, :type => :boolean, :default => false
- settings_items :name, :type => :string, :default => N_('ENGLISH TEXT')
+ settings_items :flag, type: :boolean
+ settings_items :flag_disabled_by_default, type: :boolean, default: false
+ # to test that 'name' will be symbolized (see below)
+ settings_items 'name', type: :string, default: N_('ENGLISH TEXT')
attr_accessible :flag, :name, :flag_disabled_by_default
end
@@ -26,7 +27,7 @@ class ActsAsHavingSettingsTest < ActiveSupport::TestCase
assert !block.respond_to?(:limit)
assert !block.respond_to?(:limit=)
- block_class.settings_items :limit
+ block_class.settings_items :limit, type: :integer
assert_respond_to block, :limit
assert_respond_to block, :limit=
@@ -35,7 +36,7 @@ class ActsAsHavingSettingsTest < ActiveSupport::TestCase
block.limit = 10
assert_equal 10, block.limit
- assert_equal({ :limit => 10}, block.settings)
+ assert_equal({ limit: 10}, block.settings)
end
should 'properly save the settings' do
@@ -50,7 +51,7 @@ class ActsAsHavingSettingsTest < ActiveSupport::TestCase
should 'be able to specify default values' do
block_class = Class.new(Block)
- block_class.settings_items :some_setting, :default => 10
+ block_class.settings_items :some_setting, default: 10
assert_equal 10, block_class.new.some_setting
end
@@ -75,10 +76,9 @@ class ActsAsHavingSettingsTest < ActiveSupport::TestCase
assert_equal true, obj.flag
end
- should 'symbolize keys when save' do
+ should 'have keys as symbols' do
obj = TestClass.new
- obj.settings.expects(:symbolize_keys!).once
- assert obj.save
+ assert obj.settings.all?{ |k,v| k.is_a? Symbol }
end
should 'setting_changed be true if a setting passed as parameter was changed' do
@@ -101,14 +101,14 @@ class ActsAsHavingSettingsTest < ActiveSupport::TestCase
end
should 'setting_changed be false if a setting passed as parameter was not changed but another setting is changed' do
- obj = TestClass.new(:name => 'some name')
+ obj = TestClass.new(name: 'some name')
obj.save
obj.name = 'antoher nme'
assert !obj.setting_changed?('flag')
end
should 'setting_changed be true for all changed fields' do
- obj = TestClass.new(:name => 'some name', :flag => false)
+ obj = TestClass.new(name: 'some name', flag: false)
obj.save
obj.name = 'another nme'
obj.flag = true
=====================================
test/unit/catalog_helper_test.rb
=====================================
--- a/test/unit/catalog_helper_test.rb
+++ b/test/unit/catalog_helper_test.rb
@@ -6,7 +6,7 @@ class CatalogHelperTest < ActiveSupport::TestCase
include ActionView::Helpers::TextHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
- include ActionDispatch::Assertions::SelectorAssertions
+ include ::Rails::Dom::Testing::Assertions::SelectorAssertions
def url_for(opts)
#{:controller => 'catalog', :action => 'index', :level => category.id}
=====================================
test/unit/task_test.rb
=====================================
--- a/test/unit/task_test.rb
+++ b/test/unit/task_test.rb
@@ -131,7 +131,7 @@ class TaskTest < ActiveSupport::TestCase
task.cancel
- assert_nil Task.find_by_code(task.code)
+ assert_nil Task.from_code(task.code)
end
should 'be able to find active tasks' do
@@ -139,7 +139,7 @@ class TaskTest < ActiveSupport::TestCase
task.requestor = sample_user
task.save!
- assert_not_nil Task.find_by_code(task.code)
+ assert_not_nil Task.from_code(task.code)
end
should 'use 36-chars codes by default' do
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/4afbb16c54a430d7439aee0c66ac1c6c6d8c93d0...11b47ca741839507264b4d86228bb0e71ad151f5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150405/82c45c61/attachment-0001.html>
More information about the Noosfero-dev
mailing list