Merge pull request #210 from abf/rosa-build:192-specs-for-api-defender

#192: add specs for API defender
This commit is contained in:
avm 2013-07-05 07:30:59 +04:00
commit 95beeae221
3 changed files with 29 additions and 3 deletions

View File

@ -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,6 +35,8 @@ module Modules::Observers::ActivityFeed::Issue
}
)
end
# dont remove outdated issues link
Comment.create_link_on_issues_from_item(self)
end
def send_assign_notifications(action = :create)
@ -52,9 +58,12 @@ module Modules::Observers::ActivityFeed::Issue
}
)
end
project.hooks.each{ |h| h.receive_issues(self, action) } if action == :create || 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

View File

@ -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

View File

@ -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