summaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/support/app/controllers/tickets_controller.rb6
-rw-r--r--engines/support/app/models/ticket.rb25
-rw-r--r--engines/support/app/views/tickets/_edit_form.html.haml2
-rw-r--r--engines/support/app/views/tickets/new.html.haml4
-rw-r--r--engines/support/test/functional/tickets_controller_test.rb4
-rw-r--r--engines/support/test/integration/create_ticket_test.rb36
-rw-r--r--engines/support/test/unit/ticket_test.rb4
7 files changed, 61 insertions, 20 deletions
diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb
index d552209..99357ab 100644
--- a/engines/support/app/controllers/tickets_controller.rb
+++ b/engines/support/app/controllers/tickets_controller.rb
@@ -12,6 +12,7 @@ class TicketsController < ApplicationController
def new
@ticket = Ticket.new
+ @ticket.created_by = current_user.id
@ticket.comments.build
end
@@ -22,12 +23,9 @@ class TicketsController < ApplicationController
@ticket.comments.last.posted_by = current_user.id
@ticket.comments.last.private = false unless admin?
@ticket.created_by = current_user.id
- @ticket.email = current_user.email_address if current_user.email_address
if @ticket.save
flash[:notice] = t(:thing_was_successfully_created, :thing => t(:ticket))
-
- # cannot set this until ticket has been saved, as @ticket.id will not be set
- if !logged_in? and flash[:notice]
+ if !logged_in?
flash[:notice] += " " + t(:access_ticket_text, :full_url => ticket_url(@ticket.id))
end
end
diff --git a/engines/support/app/models/ticket.rb b/engines/support/app/models/ticket.rb
index cd22758..bf5df53 100644
--- a/engines/support/app/models/ticket.rb
+++ b/engines/support/app/models/ticket.rb
@@ -19,8 +19,6 @@ class Ticket < CouchRest::Model::Base
timestamps!
- before_validation :set_email, :set_regarding_user, :on => :create
-
design do
view :by_updated_at
view :by_created_at
@@ -34,7 +32,12 @@ class Ticket < CouchRest::Model::Base
end
validates :subject, :presence => true
- validates :email, :allow_blank => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/
+
+ # email can have three states:
+ # * nil - prefilled with created_by's email
+ # * "" - cleared
+ # * valid email address
+ validates :email, :allow_blank => true, :format => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/
def self.search(options = {})
@selection = TicketSelection.new(options)
@@ -48,15 +51,15 @@ class Ticket < CouchRest::Model::Base
end
def is_creator_validated?
- !!created_by
+ created_by_user.is_a? User
end
- def set_email
- self.email = nil if self.email == ""
+ def email
+ read_attribute(:email) || created_by_user.email
end
- def set_regarding_user
- self.regarding_user = nil if self.regarding_user == ""
+ def regarding_user
+ read_attribute(:regarding_user) || created_by_user.login
end
def close
@@ -95,7 +98,11 @@ class Ticket < CouchRest::Model::Base
end
def created_by_user
- User.find(self.created_by)
+ if self.created_by
+ User.find(self.created_by) || AnonymousUser.new
+ else
+ AnonymousUser.new
+ end
end
def regarding_user_actual_user
diff --git a/engines/support/app/views/tickets/_edit_form.html.haml b/engines/support/app/views/tickets/_edit_form.html.haml
index 3675822..b8da779 100644
--- a/engines/support/app/views/tickets/_edit_form.html.haml
+++ b/engines/support/app/views/tickets/_edit_form.html.haml
@@ -1,6 +1,6 @@
:ruby
# created by user link
- if @ticket.created_by_user
+ if @ticket.is_creator_validated?
created_by = link_to @ticket.created_by_user.login, @ticket.created_by_user
else
created_by = t(:anonymous)
diff --git a/engines/support/app/views/tickets/new.html.haml b/engines/support/app/views/tickets/new.html.haml
index ab008d2..3de5fe9 100644
--- a/engines/support/app/views/tickets/new.html.haml
+++ b/engines/support/app/views/tickets/new.html.haml
@@ -8,8 +8,8 @@
= simple_form_for @ticket, :validate => true, :html => {:class => 'form-horizontal'} do |f|
= hidden_ticket_fields
= f.input :subject
- = f.input :email, input_html: {value: user.email_address}
- = f.input :regarding_user, input_html: {value: user.login}
+ = f.input :email
+ = f.input :regarding_user
= f.simple_fields_for :comments, @comment do |c|
= c.input :body, :label => t(:description), :as => :text, :input_html => {:class => "full-width", :rows=> 5}
- if admin?
diff --git a/engines/support/test/functional/tickets_controller_test.rb b/engines/support/test/functional/tickets_controller_test.rb
index d746b59..fc4a6f8 100644
--- a/engines/support/test/functional/tickets_controller_test.rb
+++ b/engines/support/test/functional/tickets_controller_test.rb
@@ -85,7 +85,7 @@ class TicketsControllerTest < ActionController::TestCase
test "should create authenticated ticket" do
- params = {:subject => "auth ticket test subject", :comments_attributes => {"0" => {"body" =>"body of test ticket"}}}
+ params = {:subject => "auth ticket test subject",:email => "", :comments_attributes => {"0" => {"body" =>"body of test ticket"}}}
login
@@ -97,7 +97,7 @@ class TicketsControllerTest < ActionController::TestCase
assert_not_nil assigns(:ticket).created_by
assert_equal assigns(:ticket).created_by, @current_user.id
- assert_equal assigns(:ticket).email, @current_user.email_address
+ assert_equal "", assigns(:ticket).email
assert_equal 1, assigns(:ticket).comments.count
assert_not_nil assigns(:ticket).comments.first.posted_by
diff --git a/engines/support/test/integration/create_ticket_test.rb b/engines/support/test/integration/create_ticket_test.rb
index 2583fc7..0f8453c 100644
--- a/engines/support/test/integration/create_ticket_test.rb
+++ b/engines/support/test/integration/create_ticket_test.rb
@@ -20,9 +20,45 @@ class CreateTicketTest < BrowserIntegrationTest
click_on 'Get Help'
fill_in 'Subject', with: 'test ticket'
fill_in 'Email', with: 'invalid data'
+ fill_in 'Regarding user', with: 'some user'
fill_in 'Description', with: 'description of the problem goes here'
click_on 'Create Ticket'
assert page.has_content?("is invalid")
+ assert_equal 'invalid data', find_field('Email').value
+ assert_equal 'some user', find_field('Regarding user').value
+ end
+
+ test "prefills fields" do
+ login FactoryGirl.create(:premium_user)
+ visit '/'
+ click_on "Support Tickets"
+ click_on "New Ticket"
+ email = "#{@user.login}@#{APP_CONFIG[:domain]}"
+ assert_equal email, find_field('Email').value
+ assert_equal @user.login, find_field('Regarding user').value
+ end
+
+ test "no prefill of email without email service" do
+ login
+ visit '/'
+ click_on "Support Tickets"
+ click_on "New Ticket"
+ assert_equal "", find_field('Email').value
+ assert_equal @user.login, find_field('Regarding user').value
+ end
+
+ test "cleared email field should remain clear" do
+ login FactoryGirl.create(:premium_user)
+ visit '/'
+ click_on "Support Tickets"
+ click_on "New Ticket"
+ fill_in 'Subject', with: 'test ticket'
+ fill_in 'Email', with: ''
+ fill_in 'Description', with: 'description of the problem goes here'
+ click_on 'Create Ticket'
+ ticket = Ticket.last
+ assert_equal "", ticket.email
+ ticket.destroy
end
end
diff --git a/engines/support/test/unit/ticket_test.rb b/engines/support/test/unit/ticket_test.rb
index f5e6ea7..678d8dc 100644
--- a/engines/support/test/unit/ticket_test.rb
+++ b/engines/support/test/unit/ticket_test.rb
@@ -27,10 +27,10 @@ class TicketTest < ActiveSupport::TestCase
end
test "creation validated" do
+ user = FactoryGirl.create :user
@sample = Ticket.new
assert !@sample.is_creator_validated?
- #p current_user
- @sample.created_by = 22 #current_user
+ @sample.created_by = user.id
assert @sample.is_creator_validated?
end