Fixed: DEPRECATION WARNING

This commit is contained in:
Vokhmin Alexey V 2015-06-05 21:56:39 +03:00
parent 5912c81d19
commit 4130672069
4 changed files with 57 additions and 61 deletions

View File

@ -41,13 +41,13 @@ ActiveAdmin.register User do
f.actions
end
action_item only: %i(show edit) do
action_item(:show) do
link_to 'Reset token', reset_token_admin_user_path(resource),
'data-method' => :put,
data: { confirm: 'Are you sure you want to reset token?' }
end
action_item only: :show do
action_item(:show) do
link_to 'Login as user', login_as_admin_user_path(resource)
end

View File

@ -1,3 +1,4 @@
SchemaPlus.setup do |config|
config.foreign_keys.auto_create = false
end
SchemaPlus::ForeignKeys.setup do |config|
config.auto_create = true # default for schema_auto_foreign_keys
# config.auto_index = true # default for schema_auto_foreign_keys
end

View File

@ -40,83 +40,83 @@ describe ApiDefender, type: :request do
context 'for anonymous user' do
it "should return the total limit" do
get_request
response.headers['X-RateLimit-Limit'].should == @rate_limit.to_s
expect(response.headers['X-RateLimit-Limit']).to eq @rate_limit.to_s
end
it "should return the correct limit usage for anonymous user" do
get_request
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-1).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-1).to_s
end
it "should return the correct limit usage for anonymous user after authenticated access" do
get_request @user
get_request
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-2).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-2).to_s
end
it "should forbidden anonymous user after exceeding limit rate" do
(@rate_limit+1).times {get_request}
response.status.should == 403
expect(response.status).to eq 403
end
end
else
it "should forbidden anonymous access" do
get_request
response.status.should == 401
expect(response.status).to eq 401
end
end
context 'for user' do
it "should return the correct limit usage for auth user" do
get_request @user
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-1).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-1).to_s
end
it "should allow auth by uname and password" do
(@rate_limit+1).times {get_request2}
get_request @user
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-1).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-1).to_s
end
it "should allow auth by email and password" do
(@rate_limit+1).times {get_request2}
get_request @user, false, true
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-1).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-1).to_s
end
it "should allow auth by token" do
(@rate_limit+1).times {get_request2}
get_request @user, true
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-1).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-1).to_s
end
it "should return the correct limit usage for auth user after other user" do
get_request2
get_request @user
response.headers['X-RateLimit-Remaining'].should == (@rate_limit-1).to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (@rate_limit-1).to_s
end
it "should forbidden user after exceeding limit rate" do
(@rate_limit+1).times {get_request @user}
response.status.should == 403
expect(response.status).to eq 403
end
it "should not forbidden user after exceeding limit rate of the other user" do
(@rate_limit+1).times {get_request2}
get_request @user
response.status.should == 200
expect(response.status).to eq 200
end
end
context 'for system user' do
it "should not return the limit usage for system user" do
get_request @system_user, true
response.headers['X-RateLimit-Limit'].should_not == @rate_limit.to_s
expect(response.headers['X-RateLimit-Limit']).to_not eq @rate_limit.to_s
end
it "should not forbidden system user" do
(@rate_limit+1).times {get_request @system_user, true}
response.status.should == 200
expect(response.status).to eq 200
end
end
@ -124,12 +124,12 @@ describe ApiDefender, type: :request 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
expect(response.headers['X-RateLimit-Limit']).to_not eq @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
expect(response.status).to eq 200
end
end

View File

@ -3,100 +3,95 @@ require "spec_helper"
describe UserMailer do
context 'On Issue create' do
let(:project) { FactoryGirl.build(:project) }
let(:issue_user) { FactoryGirl.build(:user) }
let(:issue) { FactoryGirl.build(:issue, project: project, assignee: issue_user, user: issue_user) }
let(:email) { UserMailer.new_issue_notification(issue.id, issue_user.id).deliver! }
before do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@issue_user = FactoryGirl.create(:user)
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
@issue = FactoryGirl.create(:issue, project: @project, assignee: @issue_user, user: @issue_user)
@email = UserMailer.new_issue_notification(@issue, @issue_user).deliver!
allow(User).to receive(:find) { issue_user }
allow(Issue).to receive(:find) { issue }
end
it 'should have correct subject' do
@email.subject.should == "[#{@issue.project.name}] #{@issue.title} (##{@issue.serial_id})"
expect(email.subject).to eq "[#{issue.project.name}] #{issue.title} (##{issue.serial_id})"
end
it 'should render receiver email' do
@email.to.should == [@issue_user.email]
expect(email.to).to eq [issue_user.email]
end
it 'should render the sender email' do
@email.from.should == [APP_CONFIG['do-not-reply-email']]
expect(email.from).to eq [APP_CONFIG['do-not-reply-email']]
end
it 'should assign issue project name' do
@email.body.encoded.should match(@issue.project.name)
expect(email.body.encoded).to match(issue.project.name)
end
it 'should assign issue body' do
@email.body.encoded.should match(@issue.body)
expect(email.body.encoded).to match(issue.body)
end
end
context 'On Issue assign' do
before(:each) do
let(:project) { FactoryGirl.build(:project) }
let(:issue_user) { FactoryGirl.build(:user) }
let(:user) { FactoryGirl.build(:user) }
let(:issue) { FactoryGirl.build(:issue, project: project, assignee: issue_user, user: issue_user) }
let(:email) { UserMailer.issue_assign_notification(issue, user).deliver! }
before do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@issue_user = FactoryGirl.create(:user)
@user = FactoryGirl.create(:user)
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
@issue = FactoryGirl.create(:issue, project_id: @project.id, assignee_id: @issue_user.id, user: @issue_user)
@email = UserMailer.issue_assign_notification(@issue, @user).deliver!
end
it 'should have correct subject' do
@email.subject.should == "Re: [#{@issue.project.name}] #{@issue.title} (##{@issue.serial_id})"
expect(email.subject).to eq "Re: [#{issue.project.name}] #{issue.title} (##{issue.serial_id})"
end
it 'should render receiver email' do
@email.to.should == [@user.email]
expect(email.to).to eq [user.email]
end
it 'should render the sender email' do
@email.from.should == [APP_CONFIG['do-not-reply-email']]
expect(email.from).to eq [APP_CONFIG['do-not-reply-email']]
end
it 'should assign issue title' do
@email.body.encoded.should match(@issue.title)
expect(email.body.encoded).to match(issue.title)
end
end
context 'On Comment create' do
let(:project) { FactoryGirl.build(:project) }
let(:issue_user) { FactoryGirl.build(:user) }
let(:user) { FactoryGirl.build(:user) }
let(:issue) { FactoryGirl.build(:issue, project: project, assignee: issue_user, user: issue_user) }
let(:comment) { FactoryGirl.build(:comment, commentable: issue, user: user, project: project) }
let(:email) { UserMailer.new_comment_notification(comment, issue_user.id).deliver! }
before do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@issue_user = FactoryGirl.create(:user)
@user = FactoryGirl.create(:user)
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
@issue = FactoryGirl.create(:issue, project: @project, assignee: @issue_user, user: @issue_user)
@comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project)
@email = UserMailer.new_comment_notification(@comment, @issue_user.id).deliver!
allow(User).to receive(:find) { issue_user }
end
it 'should have correct subject' do
@email.subject.should == "Re: [#{@issue.project.name}] #{@issue.title} (##{@issue.serial_id})"
expect(email.subject).to eq "Re: [#{issue.project.name}] #{issue.title} (##{issue.serial_id})"
end
it 'should render receiver email' do
@email.to.should == [@issue_user.email]
expect(email.to).to eq [issue_user.email]
end
it 'should render the sender email' do
@email.from.should == [APP_CONFIG['do-not-reply-email']]
expect(email.from).to eq [APP_CONFIG['do-not-reply-email']]
end
it 'should assign comment body' do
@email.body.encoded.should match(@comment.body)
expect(email.body.encoded).to match(comment.body)
end
end
end