summaryrefslogtreecommitdiff
path: root/help/app
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2012-10-16 15:51:35 -0700
committerjessib <jessib@riseup.net>2012-10-16 15:51:35 -0700
commit48d6c2aac9ae2bf1c140e734a576e45289c99150 (patch)
treee52e003e635ee650fbe0981dc1cb4c29c409429e /help/app
parent56273c13f54a872d02db286c90a8d5103cf7a663 (diff)
Some functional tests and other tweaks.
Diffstat (limited to 'help/app')
-rw-r--r--help/app/controllers/tickets_controller.rb6
-rw-r--r--help/app/models/ticket.rb12
-rw-r--r--help/app/models/ticket_comment.rb4
-rw-r--r--help/app/views/tickets/_comment.html.haml2
-rw-r--r--help/app/views/tickets/index.html.haml5
-rw-r--r--help/app/views/tickets/new.html.haml2
-rw-r--r--help/app/views/tickets/show.html.haml13
7 files changed, 30 insertions, 14 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb
index f4b38de..be9a2b5 100644
--- a/help/app/controllers/tickets_controller.rb
+++ b/help/app/controllers/tickets_controller.rb
@@ -1,6 +1,7 @@
class TicketsController < ApplicationController
respond_to :html #, :json
+ #has_scope :open, :type => boolean
def new
@ticket = Ticket.new
@@ -8,9 +9,9 @@ class TicketsController < ApplicationController
end
def create
- @ticket = Ticket.new #:created_by => User.current_test.id
- @ticket.attributes = params[:ticket]#.except(:comments)
+ @ticket = Ticket.new(params[:ticket])
@ticket.created_by = User.current_test.id if User.current_test
+ @ticket.email = User.current_test.email if User.current_test.email
#instead of calling add_comment, we are using comment_attributes= from the Ticket model
flash[:notice] = 'Ticket was successfully created.' if @ticket.save
@@ -35,6 +36,7 @@ class TicketsController < ApplicationController
def update
@ticket = Ticket.find(params[:id])
@ticket.attributes = params[:ticket]
+
#add_comment #or should we use ticket attributes?
# @ticket.save
if @ticket.save
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 537a7c6..76fa5c8 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -15,8 +15,8 @@ class Ticket < CouchRest::Model::Base
=end
#belongs_to :user #from leap_web_users. doesn't necessarily belong to a user though
- property :created_by, String#Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set
- property :regarding_user, String#Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil?
+ property :created_by, String, :protected => true #Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set
+ #property :regarding_user, String#Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil?
#also, both created_by and regarding_user could be nil---say user forgets username, or has general question
property :title, String
property :email, String #verify
@@ -32,6 +32,9 @@ class Ticket < CouchRest::Model::Base
#before_validation :set_created_by, :set_code, :set_email, :on => :create
before_validation :set_code, :set_email, :on => :create
+
+ #named_scope :open, :conditions => {:is_open => true} #??
+
design do
view :by_title
end
@@ -60,7 +63,7 @@ class Ticket < CouchRest::Model::Base
def set_email
self.email = nil if self.email == ""
- #self.email = current users email if is_creator_validated?
+ # in controller set to be current users email if that exists
end
def close
@@ -74,8 +77,9 @@ class Ticket < CouchRest::Model::Base
end
def comments_attributes=(attributes)
+
comment = TicketComment.new(attributes.values.first) #TicketComment.new(attributes)
- comment.posted_by = User.current_test.id if User.current_test
+ comment.posted_by = User.current_test.id if User.current_test #should we not access User.current here?
comment.posted_at = Time.now
comments << comment
diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb
index 9026bc1..a8639a1 100644
--- a/help/app/models/ticket_comment.rb
+++ b/help/app/models/ticket_comment.rb
@@ -2,13 +2,13 @@ class TicketComment
include CouchRest::Model::Embeddable
#belongs_to :ticket #is this best way to do it? will want to access all of a tickets comments, so maybe this isn't the way?
- property :posted_by, Integer#, :protected => true# maybe this should be current_user if that is set, meaning the user is logged in #String # user??
+ property :posted_by, String#, :protected => true #Integer#this should be current_user if that is set, meaning the user is logged in #cannot have it be protected and set via comments_attributes=
# if the current user is not set, then we could just say the comment comes from an 'unauthenticated user', which would be somebody with the secret URL
property :posted_at, Time#, :protected => true
#property :posted_verified, TrueClass, :protected => true #should be true if current_user is set when the comment is created
property :body, String
-
+ # ? timestamps!
validates :body, :presence => true
#before_validation :set_time#, :set_posted_by
diff --git a/help/app/views/tickets/_comment.html.haml b/help/app/views/tickets/_comment.html.haml
index 19e1ddf..1ba3bd1 100644
--- a/help/app/views/tickets/_comment.html.haml
+++ b/help/app/views/tickets/_comment.html.haml
@@ -3,6 +3,8 @@
- if User.find(comment.posted_by)
Posted by
= User.find(comment.posted_by).login
+ - else
+ Unauthenticated post
%p
Posted at
= comment.posted_at
diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml
index d2e0ea0..f328ca2 100644
--- a/help/app/views/tickets/index.html.haml
+++ b/help/app/views/tickets/index.html.haml
@@ -1,8 +1,7 @@
+Create a
+= link_to "new ticket", new_ticket_path
%h2 Tickets
- @tickets.each do |ticket|
%p
= link_to ticket.title, ticket
-%p
-Create a
-= link_to "new ticket", new_ticket_path
= #render(:partial => "ticket", :collection => @tickets)
diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml
index d784720..8c660c9 100644
--- a/help/app/views/tickets/new.html.haml
+++ b/help/app/views/tickets/new.html.haml
@@ -1,5 +1,5 @@
%h2=t :new_ticket
-= simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
+= simple_form_for(@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
= #@ticket.errors.messages
= f.input :title
= #f.input :email #if there is no current_user
diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml
index 04dd676..a9b994e 100644
--- a/help/app/views/tickets/show.html.haml
+++ b/help/app/views/tickets/show.html.haml
@@ -5,8 +5,17 @@
%h2= @ticket.title
is open?
= @ticket.is_open
-code:
-= @ticket.code
+- if @ticket.code
+ code:
+ = @ticket.code
+- if @ticket.email
+ email:
+ = @ticket.email
+- if User.find(@ticket.created_by)
+ Created by
+ = User.find(@ticket.created_by).login
+- else
+ Unauthenticated ticket creator
= render(:partial => "comment", :collection => @ticket.comments)
= simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test