Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
Updated code base, no more deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
git-jls authored and frenkel committed Dec 29, 2016
1 parent 35edd0c commit 9ca81d7
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 154 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ gem 'mysql2', "~> 0.4", group: :mysql
# Optional SQLite for development
gem 'sqlite3', "~> 1.3", group: :sqlite

gem 'rb-readline'

# authentication
gem 'devise', "~> 4.2"
gem 'devise_ldap_authenticatable', "~> 0.8"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ GEM
rb-fsevent (0.9.8)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rb-readline (0.5.3)
react-rails (1.10.0)
babel-transpiler (>= 0.7.0)
coffee-script-source (~> 1.8)
Expand Down Expand Up @@ -307,6 +308,7 @@ DEPENDENCIES
rails-controller-testing
rails-i18n (~> 5.0)
rake (~> 12.0)
rb-readline
react-rails (~> 1.10)
recaptcha (~> 4.0)
sass-rails (~> 5.0)
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/v1/tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class Api::V1::TicketsController < Api::V1::ApplicationController
include TicketsStrongParams

load_and_authorize_resource :ticket

def index
if current_user.agent && params.has_key?(:user_email)
user= User.find_by( email: Base64.urlsafe_decode64(params[:user_email]) )
user = User.find_by( email: Base64.urlsafe_decode64(params[:user_email]) )
@tickets = Ticket.by_status(:open).viewable_by(user)
else
@tickets = Ticket.by_status(:open).viewable_by(current_user)
Expand All @@ -35,9 +35,9 @@ def create
@ticket = Ticket.new(ticket_params)
if @ticket.save
NotificationMailer.incoming_message(@ticket, params[:message])
render nothing: true, status: :created
head :created
else
render nothing: true, status: :bad_request
head :bad_request
end
end
end
end
8 changes: 4 additions & 4 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class Api::V1::UsersController < Api::V1::ApplicationController
def create
@user = User.new(user_params)
if @user.save
render nothing: true, status: :created
head :created
else
render nothing: true, status: :bad_request
head :bad_request
end
end

def show
unless @user = User.find_by(email: Base64.urlsafe_decode64(params[:email]))
render nothing: true, status: :bad_request
head :bad_request
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/reply_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def set_default_notifications!(mail_message = nil)
result += label.users
end

self.notified_users = result.uniq
self.notified_users = result.to_a.uniq
end
end

Expand Down
23 changes: 18 additions & 5 deletions test/controllers/api/v1/tickets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,46 @@ class Api::V1::TicketsControllerTest < ActionController::TestCase
test 'should get index' do
sign_in users(:bob)

get :index, auth_token: users(:bob).authentication_token, :format => :json
get :index, params: {
auth_token: users(:bob).authentication_token,
format: :json
}
assert_response :success
assert_not_nil assigns(:tickets)
end

test 'should show ticket' do
sign_in users(:bob)

get :show, auth_token: users(:bob).authentication_token, id: @ticket.id, :format => :json
get :show, params: {
auth_token: users(:bob).authentication_token,
id: @ticket.id,
format: :json
}
assert_response :success
end

test 'should show tickets as nested resource' do
get :index, auth_token: users(:bob).authentication_token,
user_email: Base64.urlsafe_encode64(users(:alice).email), :format => :json
get :index, params: {
auth_token: users(:bob).authentication_token,
user_email: Base64.urlsafe_encode64(users(:alice).email),
format: :json
}
assert_response :success
end

test 'should create ticket' do
sign_in users(:bob)
assert_difference 'Ticket.count', 1 do
post :create, auth_token: users(:bob).authentication_token, ticket: {
post :create, params: {
auth_token: users(:bob).authentication_token,
ticket: {
content: 'I need help',
from: 'bob@xxxx.com',
subject: 'Remote from API',
priority: 'low'},
format: :json
}
end
assert_response :success
end
Expand Down
20 changes: 14 additions & 6 deletions test/controllers/api/v1/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ class Api::V1::UsersControllerTest < ActionController::TestCase
@charlie = users(:charlie)
end

test 'should find a User' do
get :show, auth_token: users(:alice).authentication_token, email: Base64.urlsafe_encode64(users(:alice).email), :format => :json
test 'should find a user' do
get :show, params: {
auth_token: users(:alice).authentication_token,
email: Base64.urlsafe_encode64(users(:alice).email),
format: :json
}
assert_response :success
end

test 'should create a User ' do
test 'should create a user ' do
sign_in users(:alice)
assert_difference 'User.count', 1 do
post :create, auth_token: users(:alice).authentication_token, user: {
email: 'newuser@new.com'},
post :create, params: {
auth_token: users(:alice).authentication_token,
user: {
email: 'newuser@new.com'
},
format: :json
}
end
assert_response :success
end

end
end
12 changes: 9 additions & 3 deletions test/controllers/attachments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ class AttachmentsControllerTest < ActionController::TestCase

test 'should get new' do
sign_out users(:alice)
xhr :get, :new
get :new, xhr: true
assert_response :success
end

test 'should show thumb' do
get :show, format: :thumb, id: @attachment.id
get :show, params: {
format: :thumb,
id: @attachment.id
}
assert_response :success
end


test 'should download original' do
get :show, format: :original, id: @attachment.id
get :show, params: {
format: :original,
id: @attachment.id
}
assert_response :success
end

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/email_addresses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class EmailAddressesControllerTest < ActionController::TestCase
assert_difference 'ActionMailer::Base.deliveries.size' do
assert_no_difference 'EmailAddress.where(default: true).count' do
assert_difference 'EmailAddress.count' do
post :create, email_address: { email: 'support@support.bla', default: '1' }
post :create, params: { email_address: { email: 'support@support.bla', default: '1' } }
end
end
end
Expand All @@ -65,7 +65,7 @@ class EmailAddressesControllerTest < ActionController::TestCase
sign_in @alice

assert_difference 'EmailAddress.count', -1 do
delete :destroy, id: @email_address.id
delete :destroy, params: { id: @email_address.id }
end

assert_redirected_to email_addresses_url
Expand Down
14 changes: 8 additions & 6 deletions test/controllers/labelings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class LabelingsControllerTest < ActionController::TestCase

assert_difference 'Labeling.count' do

post :create, format: :js, labeling: {
labelable_id: tickets(:problem).id,
labelable_type: 'Ticket',
label: {
name: 'Hello'
post :create, format: :js, params: {
labeling: {
labelable_id: tickets(:problem).id,
labelable_type: 'Ticket',
label: {
name: 'Hello'
}
}
}

Expand All @@ -41,7 +43,7 @@ class LabelingsControllerTest < ActionController::TestCase

test 'should remove labeling' do
assert_difference 'Labeling.count', -1 do
delete :destroy, id: @labeling, format: :js
delete :destroy, params: { id: @labeling, format: :js }

assert_response :success
end
Expand Down
40 changes: 26 additions & 14 deletions test/controllers/replies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class RepliesControllerTest < ActionController::TestCase
assert_no_difference 'ActionMailer::Base.deliveries.size' do
assert_no_difference 'Reply.count' do

post :create, reply: {
post :create, params: {
reply: {
content: '',
ticket_id: @ticket.id,
notified_user_ids: [users(:bob).id],
}
}

assert_response :success # should get a form instead of a 500
Expand All @@ -46,18 +48,20 @@ class RepliesControllerTest < ActionController::TestCase

# do we send a mail?
assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do
post :create, reply: {
post :create, params: {
reply: {
content: '<br><br><p><strong>this is in bold</strong></p>',
ticket_id: @ticket.id,
notified_user_ids: User.agents.pluck(:id),
}
}
end

mail = ActionMailer::Base.deliveries.last

# html in the html part
assert_match '<br><br><p><strong>this is in bold</strong></p>',
mail.html_part.body.decoded
mail.html_part.body.decoded

# no html in the text part
assert_match "\n\nthis is in bold\n", mail.text_part.body.decoded
Expand All @@ -78,14 +82,16 @@ class RepliesControllerTest < ActionController::TestCase
test 'reply should have attachments' do

assert_difference 'Attachment.count', 2 do
post :create, reply: {
content: '**this is in bold**',
ticket_id: @ticket.id,
notified_user_ids: [users(:bob).id],
attachments_attributes: {
'0' => { file: fixture_file_upload('attachments/default-testpage.pdf') },
'1' => { file: fixture_file_upload('attachments/default-testpage.pdf') }
}
post :create, params: {
reply: {
content: '**this is in bold**',
ticket_id: @ticket.id,
notified_user_ids: [users(:bob).id],
attachments_attributes: {
'0': { file: fixture_file_upload('attachments/default-testpage.pdf') },
'1': { file: fixture_file_upload('attachments/default-testpage.pdf') }
}
}
}
end
end
Expand All @@ -97,10 +103,12 @@ class RepliesControllerTest < ActionController::TestCase

# do we send a mail?
assert_difference 'ActionMailer::Base.deliveries.size', User.agents.count do
post :create, reply: {
post :create, params: {
reply: {
content: 'test',
ticket_id: @ticket.id,
notified_user_ids: [users(:bob).id, users(:alice).id]
}
}
end
mail = ActionMailer::Base.deliveries.last
Expand All @@ -111,9 +119,11 @@ class RepliesControllerTest < ActionController::TestCase
@ticket.status = 'closed'
@ticket.save

post :create, reply: {
post :create, params: {
reply: {
content: 're-open please',
ticket_id: @ticket.id,
}
}

@ticket.reload
Expand All @@ -125,7 +135,9 @@ class RepliesControllerTest < ActionController::TestCase
@reply.save!

@reply.reload
get :show, id: @reply.id, format: :eml
get :show, params: {
id: @reply.id, format: :eml
}
assert_response :success
end

Expand Down
26 changes: 17 additions & 9 deletions test/controllers/rules_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ class RulesControllerTest < ActionController::TestCase
test 'should get edit' do
sign_in @alice

get :edit, id: @rule
get :edit, params: {
id: @rule
}
assert_response :success
end

test 'should update' do
sign_in @alice

put :update, id: @rule, rule: {
put :update, params: {
id: @rule, rule: {
filter_field: 'subject',
}
}
assert_equal 'subject', assigns(:rule).filter_field
assert_redirected_to rules_url
Expand All @@ -67,12 +71,14 @@ class RulesControllerTest < ActionController::TestCase
sign_in @alice

assert_difference 'Rule.count' do
post :create, rule: {
filter_field: @rule.filter_field,
filter_operation: @rule.filter_operation,
filter_value: @rule.filter_value,
action_operation: @rule.action_operation,
action_value: @rule.action_value,
post :create, params: {
rule: {
filter_field: @rule.filter_field,
filter_operation: @rule.filter_operation,
filter_value: @rule.filter_value,
action_operation: @rule.action_operation,
action_value: @rule.action_value,
}
}

assert_redirected_to rules_url
Expand All @@ -83,7 +89,9 @@ class RulesControllerTest < ActionController::TestCase
sign_in @alice

assert_difference 'Rule.count', -1 do
delete :destroy, id: @rule
delete :destroy, params: {
id: @rule
}

assert_redirected_to rules_url
end
Expand Down
Loading

0 comments on commit 9ca81d7

Please sign in to comment.