Commit 8c783480acf78b192a57dbefb55a7b0b464c7fce

Authored by Leandro Santos
1 parent 19e29330

sorry - revert last 3 commits. Merge request is needed

db/migrate/20150903210329_add_proposal_discussion_plugin_simplified_abstract_to_tasks.rb
@@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
1 -class AddProposalDiscussionPluginSimplifiedAbstractToTasks < ActiveRecord::Migration  
2 - def change  
3 - add_column :tasks, :proposal_discussion_plugin_simplified_abstract, :text  
4 - add_index :tasks, :proposal_discussion_plugin_simplified_abstract  
5 - ProposalsDiscussionPlugin::ProposalTask.find_each do |t|  
6 - t.update_attribute :proposal_discussion_plugin_simplified_abstract, ProposalsDiscussionPlugin::ProposalTask.simplify(t.abstract)  
7 - end  
8 - end  
9 -end  
lib/proposals_discussion_plugin/api.rb
@@ -23,7 +23,7 @@ class ProposalsDiscussionPlugin::API &lt; Grape::API @@ -23,7 +23,7 @@ class ProposalsDiscussionPlugin::API &lt; Grape::API
23 proposal_task.requestor = current_person 23 proposal_task.requestor = current_person
24 24
25 unless proposal_task.save 25 unless proposal_task.save
26 - render_api_errors!(proposal_task.errors) 26 + render_api_errors!(proposal_task.article_object.errors.full_messages)
27 end 27 end
28 {:success => true} 28 {:success => true}
29 #present proposal_task, :with => Entities::Task, :fields => params[:fields] 29 #present proposal_task, :with => Entities::Task, :fields => params[:fields]
lib/proposals_discussion_plugin/proposal_task.rb
1 class ProposalsDiscussionPlugin::ProposalTask < Task 1 class ProposalsDiscussionPlugin::ProposalTask < Task
  2 +
2 has_and_belongs_to_many :categories, 3 has_and_belongs_to_many :categories,
3 class_name: "ProposalsDiscussionPlugin::TaskCategory", 4 class_name: "ProposalsDiscussionPlugin::TaskCategory",
4 join_table: :proposals_discussion_plugin_task_categories, 5 join_table: :proposals_discussion_plugin_task_categories,
@@ -9,13 +10,8 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task @@ -9,13 +10,8 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task
9 10
10 validates_presence_of :requestor_id, :target_id 11 validates_presence_of :requestor_id, :target_id
11 validates_associated :article_object 12 validates_associated :article_object
12 - before_save :simplify_abstract  
13 -# before_validation :simplify_abstract  
14 - validate :require_category  
15 -  
16 - validate :unique_simplified_abstract?  
17 13
18 -# validates_uniqueness_of :proposal_discussion_plugin_simplified_abstract, :scope => ['target_id'], :message => _("Cannot create duplicate proposal") 14 + validate :require_category
19 15
20 settings_items :name, :type => String 16 settings_items :name, :type => String
21 settings_items :ip_address, :type => String 17 settings_items :ip_address, :type => String
@@ -25,10 +21,6 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task @@ -25,10 +21,6 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task
25 settings_items :closing_statment, :article_parent_id 21 settings_items :closing_statment, :article_parent_id
26 22
27 23
28 - def simplify_abstract  
29 - self.proposal_discussion_plugin_simplified_abstract = ProposalsDiscussionPlugin::ProposalTask.simplify(self[:data][:article]["abstract"])  
30 - end  
31 -  
32 scope :pending_evaluated, lambda { |profile, filter_type, filter_text| 24 scope :pending_evaluated, lambda { |profile, filter_type, filter_text|
33 self 25 self
34 .to(profile) 26 .to(profile)
@@ -266,14 +258,6 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task @@ -266,14 +258,6 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task
266 parent.name if parent 258 parent.name if parent
267 end 259 end
268 260
269 - def self.simplify(s)  
270 - return nil if s.nil?  
271 - s=I18n.transliterate(s)  
272 - s.gsub!(/(^\s)|([',.?!])|(\s$)/, "")  
273 - s.gsub!(/\s{2,}/, " ")  
274 - s.downcase  
275 - end  
276 -  
277 protected 261 protected
278 262
279 def require_category 263 def require_category
@@ -282,10 +266,4 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task @@ -282,10 +266,4 @@ class ProposalsDiscussionPlugin::ProposalTask &lt; Task
282 end 266 end
283 end 267 end
284 268
285 - def unique_simplified_abstract?  
286 - sa = ProposalsDiscussionPlugin::ProposalTask.simplify(self[:data][:article]["abstract"])  
287 - r = ProposalsDiscussionPlugin::ProposalTask.find_by_sql ["SELECT 1 AS one FROM tasks WHERE tasks.type IN ('ProposalsDiscussionPlugin::ProposalTask') AND (tasks.proposal_discussion_plugin_simplified_abstract = ? AND tasks.target_id = ?) LIMIT 1", sa, target_id]  
288 - errors.add :base, _('This proposal has been previously registered') unless r.empty?  
289 - end  
290 -  
291 end 269 end
test/test_helper.rb
1 -require File.dirname(__FILE__) + '/../../../test/test_helper' 1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
test/unit/proposal_task_test.rb
1 -# encoding: UTF-8  
2 require_relative '../test_helper' 1 require_relative '../test_helper'
3 2
4 class ProposalTaskTest < ActiveSupport::TestCase 3 class ProposalTaskTest < ActiveSupport::TestCase
@@ -84,13 +83,4 @@ class ProposalTaskTest &lt; ActiveSupport::TestCase @@ -84,13 +83,4 @@ class ProposalTaskTest &lt; ActiveSupport::TestCase
84 assert task.information.present? 83 assert task.information.present?
85 end 84 end
86 85
87 - should 'not register duplicate task' do  
88 - task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => ' Alô ! ruby é legal a bêçá. seu moÇo, não Acha? '})  
89 - task.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)]  
90 - task.save!  
91 - task = ProposalsDiscussionPlugin::ProposalTask.new(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'alo ruby e legal a beca seu moco nao acha'})  
92 - task.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)]  
93 - assert !task.valid?  
94 - end  
95 -  
96 end 86 end