From 0c926e850c2cb1cef1440b6d51d881df5d70296e Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 4 Jul 2013 16:43:35 +0400 Subject: [PATCH 1/5] #192: added specs for allowed_addresses to api defender --- spec/integration/api_defender_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/integration/api_defender_spec.rb b/spec/integration/api_defender_spec.rb index c369942af..9232c883f 100644 --- a/spec/integration/api_defender_spec.rb +++ b/spec/integration/api_defender_spec.rb @@ -119,4 +119,18 @@ describe ApiDefender do response.status.should == 200 end end + + context 'for allowed_addresses' do + let(:remote_addr) { APP_CONFIG['allowed_addresses'].first } + it "should not return the limit usage for allowed address" do + get "/api/v1/users/#{@user.id}.json", {}, {'REMOTE_ADDR' => remote_addr } + response.headers['X-RateLimit-Limit'].should_not == @rate_limit.to_s + end + + it "should not forbidden allowed address" do + (@rate_limit+1).times { get "/api/v1/users/#{@user.id}.json", {}, {'REMOTE_ADDR' => remote_addr } } + response.status.should == 200 + end + end + end From 507a574fd1924358ae6e5502ffbe34ef8f49e662 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 4 Jul 2013 16:44:48 +0400 Subject: [PATCH 2/5] #192: refactoring of specs --- spec/integration/api_defender_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/integration/api_defender_spec.rb b/spec/integration/api_defender_spec.rb index 9232c883f..ecc8e71ae 100644 --- a/spec/integration/api_defender_spec.rb +++ b/spec/integration/api_defender_spec.rb @@ -120,14 +120,14 @@ describe ApiDefender do end end - context 'for allowed_addresses' do + context 'for allowed addresses' do let(:remote_addr) { APP_CONFIG['allowed_addresses'].first } - it "should not return the limit usage for allowed address" do + it 'should not return the limit usage for allowed address' do get "/api/v1/users/#{@user.id}.json", {}, {'REMOTE_ADDR' => remote_addr } response.headers['X-RateLimit-Limit'].should_not == @rate_limit.to_s end - it "should not forbidden allowed address" do + it 'should not forbidden allowed address' do (@rate_limit+1).times { get "/api/v1/users/#{@user.id}.json", {}, {'REMOTE_ADDR' => remote_addr } } response.status.should == 200 end From 4274e397bd3ed99b884ce6ff2c07f82f9efc82c2 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 4 Jul 2013 19:35:01 +0600 Subject: [PATCH 3/5] fixed bug with creating links to the issue --- lib/modules/observers/activity_feed/issue.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/modules/observers/activity_feed/issue.rb b/lib/modules/observers/activity_feed/issue.rb index d2f9736be..90fb6e4ff 100644 --- a/lib/modules/observers/activity_feed/issue.rb +++ b/lib/modules/observers/activity_feed/issue.rb @@ -31,6 +31,8 @@ module Modules::Observers::ActivityFeed::Issue } ) end + project.hooks.each{ |h| h.receive_issues(self, action) } + Comment.create_link_on_issues_from_item(self) end def send_assign_notifications(action = :create) @@ -52,7 +54,7 @@ module Modules::Observers::ActivityFeed::Issue } ) end - project.hooks.each{ |h| h.receive_issues(self, action) } if action == :create || status_changed? + project.hooks.each{ |h| h.receive_issues(self, action) } if status_changed? # dont remove outdated issues link Comment.create_link_on_issues_from_item(self) end From cb36a6d6da69656217a8a494778e6138868515d7 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 4 Jul 2013 17:55:41 +0400 Subject: [PATCH 4/5] #192: fixed undefined method --- lib/modules/observers/activity_feed/issue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/observers/activity_feed/issue.rb b/lib/modules/observers/activity_feed/issue.rb index 90fb6e4ff..8866563ee 100644 --- a/lib/modules/observers/activity_feed/issue.rb +++ b/lib/modules/observers/activity_feed/issue.rb @@ -31,7 +31,7 @@ module Modules::Observers::ActivityFeed::Issue } ) end - project.hooks.each{ |h| h.receive_issues(self, action) } + project.hooks.each{ |h| h.receive_issues(self, :create) } Comment.create_link_on_issues_from_item(self) end From 3f42dfcd358f9b2c9d998d835d9596816550df61 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 4 Jul 2013 18:08:07 +0400 Subject: [PATCH 5/5] #192: updated factory, some refactoring of Issue observer --- lib/modules/observers/activity_feed/issue.rb | 15 +++++++++++---- spec/factories/issues.rb | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/modules/observers/activity_feed/issue.rb b/lib/modules/observers/activity_feed/issue.rb index 8866563ee..510b26011 100644 --- a/lib/modules/observers/activity_feed/issue.rb +++ b/lib/modules/observers/activity_feed/issue.rb @@ -3,9 +3,13 @@ module Modules::Observers::ActivityFeed::Issue extend ActiveSupport::Concern included do - after_commit :new_issue_notifications, :on => :create - after_commit :send_assign_notifications, :on => :create + after_commit :new_issue_notifications, :on => :create + + after_commit :send_assign_notifications, :on => :create after_commit -> { send_assign_notifications(:update) }, :on => :update + + after_commit :send_hooks, :on => :create + after_commit -> { send_hooks(:update) }, :on => :update, :if => :status_changed? end private @@ -31,7 +35,7 @@ module Modules::Observers::ActivityFeed::Issue } ) end - project.hooks.each{ |h| h.receive_issues(self, :create) } + # dont remove outdated issues link Comment.create_link_on_issues_from_item(self) end @@ -54,9 +58,12 @@ module Modules::Observers::ActivityFeed::Issue } ) end - project.hooks.each{ |h| h.receive_issues(self, action) } if status_changed? # dont remove outdated issues link Comment.create_link_on_issues_from_item(self) end + def send_hooks(action = :create) + project.hooks.each{ |h| h.receive_issues(self, action) } + end + end \ No newline at end of file diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 1bacc7763..1ba6ed1e3 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -7,6 +7,9 @@ FactoryGirl.define do association :user, :factory => :user association :assignee, :factory => :user status "open" + # Hooks for #after_commit after(:create) { |i| i.send(:new_issue_notifications) } + after(:create) { |i| i.send(:send_assign_notifications) } + after(:create) { |i| i.send(:send_hooks) } end end