From 02426b7f143e82447ff41a604c286b556ab8d3a5 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 09:06:31 +0200 Subject: use i18n.missing_translations This will print missing translation keys at the end of the tests --- Gemfile | 1 + Gemfile.lock | 3 +++ test/test_helper.rb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Gemfile b/Gemfile index 816cc4a..ae11e0e 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,7 @@ end group :test, :development do gem 'thin' + gem 'i18n-missing_translations' end group :assets do diff --git a/Gemfile.lock b/Gemfile.lock index 53e0d0b..2c229f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -122,6 +122,8 @@ GEM hike (1.2.3) http_accept_language (2.0.0) i18n (0.6.9) + i18n-missing_translations (0.0.2) + i18n (~> 0.6.0) journey (1.0.4) jquery-rails (3.0.4) railties (>= 3.0, < 5.0) @@ -254,6 +256,7 @@ DEPENDENCIES haml (~> 3.1.7) haml-rails (~> 0.3.4) http_accept_language + i18n-missing_translations jquery-rails json kaminari (= 0.13.0) diff --git a/test/test_helper.rb b/test/test_helper.rb index d001ac7..7959ddb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -27,4 +27,6 @@ class ActiveSupport::TestCase File.join(Rails.root, 'test', 'files', name) end + require 'i18n/missing_translations' + at_exit { I18n.missing_translations.dump } end -- cgit v1.2.3 From e7d6bcce2a04a049926e75074605a2e7f91ede1a Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 09:08:42 +0200 Subject: move comment related tests out of TicketControllerTest This controller does too much - so the tests are also getting large and hard to keep track of --- .../test/functional/ticket_comments_test.rb | 89 ++++++++++++++++++++++ .../test/functional/tickets_controller_test.rb | 78 ------------------- 2 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 engines/support/test/functional/ticket_comments_test.rb diff --git a/engines/support/test/functional/ticket_comments_test.rb b/engines/support/test/functional/ticket_comments_test.rb new file mode 100644 index 0000000..e30a018 --- /dev/null +++ b/engines/support/test/functional/ticket_comments_test.rb @@ -0,0 +1,89 @@ +require 'test_helper' + +class TicketsCommentsTest < ActionController::TestCase + tests TicketsController + + teardown do + # destroy all tickets that were created during the test + Ticket.all.each{|t| t.destroy} + end + + test "add comment to unauthenticated ticket" do + ticket = FactoryGirl.create :ticket, :created_by => nil + + assert_difference('Ticket.find(ticket.id).comments.count') do + put :update, :id => ticket.id, + :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } + end + + assert_equal ticket, assigns(:ticket) # still same ticket, with different comments + assert_not_equal ticket.comments, assigns(:ticket).comments # ticket == assigns(:ticket), but they have different comments (which we want) + + end + + + test "add comment to own authenticated ticket" do + + login + ticket = FactoryGirl.create :ticket, :created_by => @current_user.id + + #they should be able to comment if it is their ticket: + assert_difference('Ticket.find(ticket.id).comments.count') do + put :update, :id => ticket.id, + :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } + end + assert_not_equal ticket.comments, assigns(:ticket).comments + assert_not_nil assigns(:ticket).comments.last.posted_by + assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id + + end + + + test "cannot comment if it is not your ticket" do + + other_user = find_record :user + login :is_admin? => false, :email => nil + ticket = FactoryGirl.create :ticket, :created_by => other_user.id + # they should *not* be able to comment if it is not their ticket + put :update, :id => ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"not allowed comment"}} } + assert_response :redirect + assert_access_denied + + assert_equal ticket.comments.map(&:body), assigns(:ticket).comments.map(&:body) + + end + + + test "admin add comment to authenticated ticket" do + + other_user = find_record :user + login :is_admin? => true + + ticket = FactoryGirl.create :ticket, :created_by => other_user.id + + #admin should be able to comment: + assert_difference('Ticket.find(ticket.id).comments.count') do + put :update, :id => ticket.id, + :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } + end + assert_not_equal ticket.comments, assigns(:ticket).comments + assert_not_nil assigns(:ticket).comments.last.posted_by + assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id + end + + test "commenting on a ticket adds to tickets that are mine" do + testticket = FactoryGirl.create :ticket + user = find_record :admin_user + login user + get :index, {:user_id => user.id, :open_status => "open"} + assert_difference('assigns[:all_tickets].count') do + put :update, :id => testticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}}} + get :index, {:user_id => user.id, :open_status => "open"} + end + + assert assigns(:all_tickets).include?(assigns(:ticket)) + assert_not_nil assigns(:ticket).comments.last.posted_by + assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id + end + +end diff --git a/engines/support/test/functional/tickets_controller_test.rb b/engines/support/test/functional/tickets_controller_test.rb index fc4a6f8..bb86dad 100644 --- a/engines/support/test/functional/tickets_controller_test.rb +++ b/engines/support/test/functional/tickets_controller_test.rb @@ -104,69 +104,6 @@ class TicketsControllerTest < ActionController::TestCase assert_equal assigns(:ticket).comments.first.posted_by, @current_user.id end - test "add comment to unauthenticated ticket" do - ticket = FactoryGirl.create :ticket, :created_by => nil - - assert_difference('Ticket.find(ticket.id).comments.count') do - put :update, :id => ticket.id, - :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } - end - - assert_equal ticket, assigns(:ticket) # still same ticket, with different comments - assert_not_equal ticket.comments, assigns(:ticket).comments # ticket == assigns(:ticket), but they have different comments (which we want) - - end - - - test "add comment to own authenticated ticket" do - - login - ticket = FactoryGirl.create :ticket, :created_by => @current_user.id - - #they should be able to comment if it is their ticket: - assert_difference('Ticket.find(ticket.id).comments.count') do - put :update, :id => ticket.id, - :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } - end - assert_not_equal ticket.comments, assigns(:ticket).comments - assert_not_nil assigns(:ticket).comments.last.posted_by - assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id - - end - - - test "cannot comment if it is not your ticket" do - - other_user = find_record :user - login :is_admin? => false, :email => nil - ticket = FactoryGirl.create :ticket, :created_by => other_user.id - # they should *not* be able to comment if it is not their ticket - put :update, :id => ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"not allowed comment"}} } - assert_response :redirect - assert_access_denied - - assert_equal ticket.comments.map(&:body), assigns(:ticket).comments.map(&:body) - - end - - - test "admin add comment to authenticated ticket" do - - other_user = find_record :user - login :is_admin? => true - - ticket = FactoryGirl.create :ticket, :created_by => other_user.id - - #admin should be able to comment: - assert_difference('Ticket.find(ticket.id).comments.count') do - put :update, :id => ticket.id, - :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } - end - assert_not_equal ticket.comments, assigns(:ticket).comments - assert_not_nil assigns(:ticket).comments.last.posted_by - assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id - end - test "tickets by admin" do other_user = find_record :user ticket = FactoryGirl.create :ticket, :created_by => other_user.id @@ -196,21 +133,6 @@ class TicketsControllerTest < ActionController::TestCase assert !assigns(:all_tickets).include?(testticket) end - test "commenting on a ticket adds to tickets that are mine" do - testticket = FactoryGirl.create :ticket - user = find_record :admin_user - login user - get :index, {:user_id => user.id, :open_status => "open"} - assert_difference('assigns[:all_tickets].count') do - put :update, :id => testticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}}} - get :index, {:user_id => user.id, :open_status => "open"} - end - - assert assigns(:all_tickets).include?(assigns(:ticket)) - assert_not_nil assigns(:ticket).comments.last.posted_by - assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id - end - test "admin ticket ordering" do tickets = FactoryGirl.create_list :ticket, 2 -- cgit v1.2.3 From 730e31017109994c24db431fde12f575ed5c1467 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 09:13:25 +0200 Subject: FlashResponder will automagically add flash messages --- app/views/layouts/_messages.html.haml | 2 +- config/initializers/i18n.rb | 4 ++++ config/locales/en.yml | 6 ++++++ engines/support/app/controllers/tickets_controller.rb | 13 ++++++------- lib/extensions/couchrest.rb | 3 +++ 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/views/layouts/_messages.html.haml b/app/views/layouts/_messages.html.haml index 7ff985f..18be54f 100644 --- a/app/views/layouts/_messages.html.haml +++ b/app/views/layouts/_messages.html.haml @@ -1,6 +1,6 @@ #messages - flash.each do |name, msg| - if msg.is_a?(String) - %div{:class => "alert alert-#{name == :notice ? "success" : "error"}"} + %div{:class => "alert alert-#{name == :notice ? "success" : name}"} %a.close{"data-dismiss" => "alert"} × = content_tag :div, format_flash(msg), :id => "flash_#{name}" diff --git a/config/initializers/i18n.rb b/config/initializers/i18n.rb index c277a22..b209d00 100644 --- a/config/initializers/i18n.rb +++ b/config/initializers/i18n.rb @@ -8,3 +8,7 @@ MATCH_LOCALE = /(#{I18n.available_locales.join('|')})/ # I18n.available_locales is always an array of symbols, but for comparison with # params we need it to be an array of strings. LOCALES_STRING = I18n.available_locales.map(&:to_s) + +# enable using the cascade option +# see svenfuchs.com/2011/2/11/organizing-translations-with-i18n-cascade-and-i18n-missingtranslations +I18n::Backend::Simple.send(:include, I18n::Backend::Cascade) diff --git a/config/locales/en.yml b/config/locales/en.yml index 899d659..a7a76a8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,10 @@ en: + flash: + success: "%{resource} was successfully saved." + create: + success: "%{resource} was successfully created." + update: + success: "%{resource} was successfully updated." home: Home privacy_policy: Privacy Policy terms_of_service: Terms of Service diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb index 99357ab..19663c3 100644 --- a/engines/support/app/controllers/tickets_controller.rb +++ b/engines/support/app/controllers/tickets_controller.rb @@ -23,11 +23,8 @@ class TicketsController < ApplicationController @ticket.comments.last.posted_by = current_user.id @ticket.comments.last.private = false unless admin? @ticket.created_by = current_user.id - if @ticket.save - flash[:notice] = t(:thing_was_successfully_created, :thing => t(:ticket)) - if !logged_in? - flash[:notice] += " " + t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) - end + if @ticket.save && !logged_in? + flash[:success] = t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) end respond_with(@ticket, :location => auto_ticket_path(@ticket)) end @@ -62,10 +59,8 @@ class TicketsController < ApplicationController end if @ticket.changed? and @ticket.save - flash[:notice] = t(:changes_saved) redirect_to_tickets else - flash[:error] = @ticket.errors.full_messages.join(". ") if @ticket.changed? redirect_to auto_ticket_path(@ticket) end end @@ -88,6 +83,10 @@ class TicketsController < ApplicationController @title = t(:tickets) end + def self.responder + Responders::FlashResponder + end + private # diff --git a/lib/extensions/couchrest.rb b/lib/extensions/couchrest.rb index 95f5d92..0e5051a 100644 --- a/lib/extensions/couchrest.rb +++ b/lib/extensions/couchrest.rb @@ -1,5 +1,8 @@ module CouchRest module Model + class Base + extend ActiveModel::Naming + end module Designs class View -- cgit v1.2.3 From 29fd85f605ee41275e383681a6b3e8ea0615d525 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 11:18:28 +0200 Subject: splitting up long functional test case --- engines/support/test/factories.rb | 12 +++- .../test/functional/ticket_comments_test.rb | 16 ++++- .../test/functional/tickets_controller_test.rb | 74 +++++++++++++--------- 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/engines/support/test/factories.rb b/engines/support/test/factories.rb index be04f15..bcf41e8 100644 --- a/engines/support/test/factories.rb +++ b/engines/support/test/factories.rb @@ -6,13 +6,23 @@ FactoryGirl.define do factory :ticket_with_comment do comments_attributes do - { "0" => { "body" => Faker::Lorem.sentences.join(" ") } } + { "0" => { + "body" => Faker::Lorem.sentences.join(" "), + "posted_by" => created_by + } } end end factory :ticket_with_creator do created_by { FactoryGirl.create(:user).id } end + + end + + # TicketComments can not be saved. so only use this with build + # and add to a ticket afterwards + factory :ticket_comment do + body { Faker::Lorem.sentences.join(" ") } end end diff --git a/engines/support/test/functional/ticket_comments_test.rb b/engines/support/test/functional/ticket_comments_test.rb index e30a018..5cbe233 100644 --- a/engines/support/test/functional/ticket_comments_test.rb +++ b/engines/support/test/functional/ticket_comments_test.rb @@ -39,8 +39,7 @@ class TicketsCommentsTest < ActionController::TestCase end - test "cannot comment if it is not your ticket" do - + test "cannot comment if it is another users ticket" do other_user = find_record :user login :is_admin? => false, :email => nil ticket = FactoryGirl.create :ticket, :created_by => other_user.id @@ -50,10 +49,23 @@ class TicketsCommentsTest < ActionController::TestCase assert_access_denied assert_equal ticket.comments.map(&:body), assigns(:ticket).comments.map(&:body) + end + test "authenticated comment on an anonymous ticket adds to my tickets" do + login + ticket = FactoryGirl.create :ticket + other_ticket = FactoryGirl.create :ticket + put :update, :id => ticket.id, + :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } + assert_not_nil assigns(:ticket).comments.last.posted_by + assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id + visible_tickets = Ticket.search admin_status: 'mine', + user_id: @current_user.id, is_admin: false + assert_equal [ticket], visible_tickets.all end + test "admin add comment to authenticated ticket" do other_user = find_record :user diff --git a/engines/support/test/functional/tickets_controller_test.rb b/engines/support/test/functional/tickets_controller_test.rb index bb86dad..acc088f 100644 --- a/engines/support/test/functional/tickets_controller_test.rb +++ b/engines/support/test/functional/tickets_controller_test.rb @@ -155,51 +155,63 @@ class TicketsControllerTest < ActionController::TestCase end - test "tickets for regular user" do + test "own tickets include tickets commented upon" do login ticket = FactoryGirl.create :ticket other_ticket = FactoryGirl.create :ticket - - put :update, :id => ticket.id, - :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } - assert_not_nil assigns(:ticket).comments.last.posted_by - assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id + comment = FactoryGirl.build(:ticket_comment, posted_by: @current_user.id) + ticket.comments << comment + ticket.save get :index, {:open_status => "open"} assert assigns(:all_tickets).count > 0 assert assigns(:all_tickets).include?(ticket) assert !assigns(:all_tickets).include?(other_ticket) + end - # user should have one more ticket if a new tick gets a comment by this user - assert_difference('assigns[:all_tickets].count') do - put :update, :id => other_ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}}} - get :index, {:open_status => "open"} - end - assert assigns(:all_tickets).include?(other_ticket) - - # if we close one ticket, the user should have 1 less open ticket - assert_difference('assigns[:all_tickets].count', -1) do - other_ticket.reload - other_ticket.close - other_ticket.save - get :index, {:open_status => "open"} - end + test "list all tickets created by user" do + login + ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + other_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + get :index, {:open_status => "open"} + assert_equal 2, assigns[:all_tickets].count + end - number_open_tickets = assigns(:all_tickets).count + test "closing ticket removes from open tickets list" do + login + ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + other_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + other_ticket.reload + other_ticket.close + other_ticket.save + get :index, {:open_status => "open"} + assert_equal 1, assigns[:all_tickets].count + end - # look at closed tickets: + test "list closed tickets only" do + login + open_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + closed_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id, is_open: false get :index, {:open_status => "closed"} - assert !assigns(:all_tickets).include?(ticket) - assert assigns(:all_tickets).include?(other_ticket) - number_closed_tickets = assigns(:all_tickets).count + assert_equal [closed_ticket], assigns(:all_tickets).all + end - # all tickets should equal closed + open + test "list all tickets inludes closed + open" do + login + open_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + closed_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id, is_open: false get :index, {:open_status => "all"} - assert assigns(:all_tickets).include?(ticket) - assert assigns(:all_tickets).include?(other_ticket) - assert_equal assigns(:all_tickets).count, number_closed_tickets + number_open_tickets - - + assert_equal 2, assigns(:all_tickets).count + assert assigns(:all_tickets).include?(open_ticket) + assert assigns(:all_tickets).include?(closed_ticket) end end -- cgit v1.2.3 From 7638970e233eaebc48abd499c37c274b48c97a96 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 11:41:26 +0200 Subject: separate tests for the ticket list from main controller test --- .../test/functional/tickets_controller_test.rb | 120 ++------------------ .../support/test/functional/tickets_list_test.rb | 122 +++++++++++++++++++++ 2 files changed, 131 insertions(+), 111 deletions(-) create mode 100644 engines/support/test/functional/tickets_list_test.rb diff --git a/engines/support/test/functional/tickets_controller_test.rb b/engines/support/test/functional/tickets_controller_test.rb index acc088f..e103d01 100644 --- a/engines/support/test/functional/tickets_controller_test.rb +++ b/engines/support/test/functional/tickets_controller_test.rb @@ -1,5 +1,14 @@ require 'test_helper' +# +# Tests for the basic actions in the TicketsController +# +# Also see +# TicketCommentsTest +# TicketsListTest +# +# for detailed functional tests for comments and index action. +# class TicketsControllerTest < ActionController::TestCase teardown do @@ -103,116 +112,5 @@ class TicketsControllerTest < ActionController::TestCase assert_not_nil assigns(:ticket).comments.first.posted_by assert_equal assigns(:ticket).comments.first.posted_by, @current_user.id end - - test "tickets by admin" do - other_user = find_record :user - ticket = FactoryGirl.create :ticket, :created_by => other_user.id - - login :is_admin? => true - - get :index, {:admin_status => "all", :open_status => "open"} - assert assigns(:all_tickets).count > 0 - - # if we close one ticket, the admin should have 1 less open ticket - assert_difference('assigns[:all_tickets].count', -1) do - assigns(:tickets).first.close - assigns(:tickets).first.save - get :index, {:admin_status => "all", :open_status => "open"} - end - end - - - test "admin_status mine vs all" do - testticket = FactoryGirl.create :ticket - user = find_record :user - login :is_admin? => true, :email => nil - - get :index, {:open_status => "open"} - assert assigns(:all_tickets).include?(testticket) - get :index, {:user_id => user.id, :open_status => "open"} - assert !assigns(:all_tickets).include?(testticket) - end - - test "admin ticket ordering" do - tickets = FactoryGirl.create_list :ticket, 2 - - login :is_admin? => true, :email => nil - get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_desc'} - - # this will consider all tickets, not just those on first page - first_tick = assigns(:all_tickets).all.first - last_tick = assigns(:all_tickets).all.last - assert first_tick.created_at > last_tick.created_at - - # and now reverse order: - get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_asc'} - - assert_equal first_tick, assigns(:all_tickets).last - assert_equal last_tick, assigns(:all_tickets).first - - assert_not_equal first_tick, assigns(:all_tickets).first - assert_not_equal last_tick, assigns(:all_tickets).last - - end - - test "own tickets include tickets commented upon" do - login - ticket = FactoryGirl.create :ticket - other_ticket = FactoryGirl.create :ticket - comment = FactoryGirl.build(:ticket_comment, posted_by: @current_user.id) - ticket.comments << comment - ticket.save - - get :index, {:open_status => "open"} - assert assigns(:all_tickets).count > 0 - assert assigns(:all_tickets).include?(ticket) - assert !assigns(:all_tickets).include?(other_ticket) - end - - test "list all tickets created by user" do - login - ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id - other_ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id - get :index, {:open_status => "open"} - assert_equal 2, assigns[:all_tickets].count - end - - test "closing ticket removes from open tickets list" do - login - ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id - other_ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id - other_ticket.reload - other_ticket.close - other_ticket.save - get :index, {:open_status => "open"} - assert_equal 1, assigns[:all_tickets].count - end - - test "list closed tickets only" do - login - open_ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id - closed_ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id, is_open: false - get :index, {:open_status => "closed"} - assert_equal [closed_ticket], assigns(:all_tickets).all - end - - test "list all tickets inludes closed + open" do - login - open_ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id - closed_ticket = FactoryGirl.create :ticket_with_comment, - created_by: @current_user.id, is_open: false - get :index, {:open_status => "all"} - assert_equal 2, assigns(:all_tickets).count - assert assigns(:all_tickets).include?(open_ticket) - assert assigns(:all_tickets).include?(closed_ticket) - end - end diff --git a/engines/support/test/functional/tickets_list_test.rb b/engines/support/test/functional/tickets_list_test.rb new file mode 100644 index 0000000..4c4cdef --- /dev/null +++ b/engines/support/test/functional/tickets_list_test.rb @@ -0,0 +1,122 @@ +require 'test_helper' + +class TicketsListTest < ActionController::TestCase + tests TicketsController + + teardown do + # destroy all records that were created during the test + Ticket.all.each{|t| t.destroy} + User.all.each{|u| u.account.destroy} + end + + + test "tickets by admin" do + other_user = find_record :user + ticket = FactoryGirl.create :ticket, :created_by => other_user.id + + login :is_admin? => true + + get :index, {:admin_status => "all", :open_status => "open"} + assert assigns(:all_tickets).count > 0 + + # if we close one ticket, the admin should have 1 less open ticket + assert_difference('assigns[:all_tickets].count', -1) do + assigns(:tickets).first.close + assigns(:tickets).first.save + get :index, {:admin_status => "all", :open_status => "open"} + end + end + + + test "admin_status mine vs all" do + testticket = FactoryGirl.create :ticket + user = find_record :user + login :is_admin? => true, :email => nil + + get :index, {:open_status => "open"} + assert assigns(:all_tickets).include?(testticket) + get :index, {:user_id => user.id, :open_status => "open"} + assert !assigns(:all_tickets).include?(testticket) + end + + test "admin ticket ordering" do + tickets = FactoryGirl.create_list :ticket, 2 + + login :is_admin? => true, :email => nil + get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_desc'} + + # this will consider all tickets, not just those on first page + first_tick = assigns(:all_tickets).all.first + last_tick = assigns(:all_tickets).all.last + assert first_tick.created_at > last_tick.created_at + + # and now reverse order: + get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_asc'} + + assert_equal first_tick, assigns(:all_tickets).last + assert_equal last_tick, assigns(:all_tickets).first + + assert_not_equal first_tick, assigns(:all_tickets).first + assert_not_equal last_tick, assigns(:all_tickets).last + + end + + test "own tickets include tickets commented upon" do + login + ticket = FactoryGirl.create :ticket + other_ticket = FactoryGirl.create :ticket + comment = FactoryGirl.build(:ticket_comment, posted_by: @current_user.id) + ticket.comments << comment + ticket.save + + get :index, {:open_status => "open"} + assert assigns(:all_tickets).count > 0 + assert assigns(:all_tickets).include?(ticket) + assert !assigns(:all_tickets).include?(other_ticket) + end + + test "list all tickets created by user" do + login + ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + other_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + get :index, {:open_status => "open"} + assert_equal 2, assigns[:all_tickets].count + end + + test "closing ticket removes from open tickets list" do + login + ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + other_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + other_ticket.reload + other_ticket.close + other_ticket.save + get :index, {:open_status => "open"} + assert_equal 1, assigns[:all_tickets].count + end + + test "list closed tickets only" do + login + open_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + closed_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id, is_open: false + get :index, {:open_status => "closed"} + assert_equal [closed_ticket], assigns(:all_tickets).all + end + + test "list all tickets inludes closed + open" do + login + open_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + closed_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id, is_open: false + get :index, {:open_status => "all"} + assert_equal 2, assigns(:all_tickets).count + assert assigns(:all_tickets).include?(open_ticket) + assert assigns(:all_tickets).include?(closed_ticket) + end +end -- cgit v1.2.3 From 467dd712a19d48fc653cfc0e58201e6657d2c1f9 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 12:30:55 +0200 Subject: split up and refactor TicketController#update close and open actions for plain opening and closing the tickets respond_with so fields are not cleared on invalid update the custom actions are not strictly restful. But adding a subresource felt like too much overhead and is conceptually hard to grasp (so we destroy the openess of the ticket to close it?). --- .../support/app/controllers/tickets_controller.rb | 66 ++++++++++------------ engines/support/app/models/ticket.rb | 2 + .../support/app/views/tickets/_comments.html.haml | 8 +++ .../support/app/views/tickets/_edit_form.html.haml | 7 ++- engines/support/app/views/tickets/edit.html.haml | 5 ++ engines/support/app/views/tickets/show.html.haml | 9 +-- engines/support/config/routes.rb | 14 ++++- .../test/functional/tickets_controller_test.rb | 17 ++++++ 8 files changed, 78 insertions(+), 50 deletions(-) create mode 100644 engines/support/app/views/tickets/_comments.html.haml create mode 100644 engines/support/app/views/tickets/edit.html.haml diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb index 19663c3..bb98277 100644 --- a/engines/support/app/controllers/tickets_controller.rb +++ b/engines/support/app/controllers/tickets_controller.rb @@ -5,8 +5,8 @@ class TicketsController < ApplicationController #has_scope :open, :type => boolean before_filter :require_login, :only => [:index] - before_filter :fetch_ticket, :only => [:show, :update, :destroy] - before_filter :require_ticket_access, :only => [:show, :update, :destroy] + before_filter :fetch_ticket, except: [:new, :create, :index] + before_filter :require_ticket_access, except: [:new, :create, :index] before_filter :fetch_user before_filter :set_title @@ -37,33 +37,32 @@ class TicketsController < ApplicationController end end - def update - if params[:button] == 'close' - @ticket.is_open = false - @ticket.save - redirect_to_tickets - elsif params[:button] == 'open' - @ticket.is_open = true - @ticket.save - redirect_to auto_ticket_path(@ticket) - else - @ticket.attributes = cleanup_ticket_params(params[:ticket]) + def close + @ticket.close + @ticket.save + redirect_to redirection_path + end - if params[:button] == 'reply_and_close' - @ticket.close - end + def open + @ticket.reopen + @ticket.save + redirect_to redirection_path + end - if @ticket.comments_changed? - @ticket.comments.last.posted_by = current_user.id - @ticket.comments.last.private = false unless admin? - end + def update + @ticket.attributes = cleanup_ticket_params(params[:ticket]) - if @ticket.changed? and @ticket.save - redirect_to_tickets - else - redirect_to auto_ticket_path(@ticket) - end + if params[:button] == 'reply_and_close' + @ticket.close + end + + if @ticket.comments_changed? + @ticket.comments.last.posted_by = current_user.id + @ticket.comments.last.private = false unless admin? end + + @ticket.save + respond_with @ticket, location: redirection_path end def index @@ -90,19 +89,14 @@ class TicketsController < ApplicationController private # - # redirects to ticket index, if appropriate. - # otherwise, just redirects to @ticket + # ticket index, if appropriate. + # otherwise, just @ticket # - def redirect_to_tickets - if logged_in? - if params[:button] == t(:reply_and_close) - redirect_to auto_tickets_path - else - redirect_to auto_ticket_path(@ticket) - end + def redirection_path + if logged_in? && params[:button] == t(:reply_and_close) + auto_tickets_path else - # if we are not logged in, there is no index to view - redirect_to auto_ticket_path(@ticket) + auto_ticket_path(@ticket) end end diff --git a/engines/support/app/models/ticket.rb b/engines/support/app/models/ticket.rb index bf5df53..161507c 100644 --- a/engines/support/app/models/ticket.rb +++ b/engines/support/app/models/ticket.rb @@ -39,6 +39,8 @@ class Ticket < CouchRest::Model::Base # * valid email address validates :email, :allow_blank => true, :format => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/ + # validates :comments, presence: true + def self.search(options = {}) @selection = TicketSelection.new(options) @selection.tickets diff --git a/engines/support/app/views/tickets/_comments.html.haml b/engines/support/app/views/tickets/_comments.html.haml new file mode 100644 index 0000000..0a3b345 --- /dev/null +++ b/engines/support/app/views/tickets/_comments.html.haml @@ -0,0 +1,8 @@ +%table.table.table-striped.table-bordered + %tbody + = render :partial => 'tickets/comment', :collection => @ticket.comments + %tr + %td.user + = current_user.login || t(:anonymous) + %td.comment + = render 'tickets/new_comment_form' diff --git a/engines/support/app/views/tickets/_edit_form.html.haml b/engines/support/app/views/tickets/_edit_form.html.haml index b8da779..22815f2 100644 --- a/engines/support/app/views/tickets/_edit_form.html.haml +++ b/engines/support/app/views/tickets/_edit_form.html.haml @@ -17,17 +17,18 @@ regarding_user_link = '' end -= simple_form_for @ticket do |f| +- url = url_for([@ticket.is_open? ? :close : :open, @ticket]) += simple_form_for @ticket, url: url do |f| = hidden_ticket_fields %p.first - if @ticket.is_open? %span.label.label-info %b{style: 'padding:10px'}= t(:open) - = f.button :loading, t(:close), value: 'close', class: 'btn-mini' + = f.button :loading, t(:close), class: 'btn-mini' - else %span.label.label-success %b{style: 'padding:10px'}= t(:closed) - = f.button :loading, t(:open), value: 'open', class: 'btn-mini' + = f.button :loading, t(:open), class: 'btn-mini' %span.label.label-clear= t(:created_by_on, :user => created_by, :time => @ticket.created_at.to_s(:short)).html_safe = simple_form_for @ticket do |f| = hidden_ticket_fields diff --git a/engines/support/app/views/tickets/edit.html.haml b/engines/support/app/views/tickets/edit.html.haml new file mode 100644 index 0000000..99afa2a --- /dev/null +++ b/engines/support/app/views/tickets/edit.html.haml @@ -0,0 +1,5 @@ +- @show_navigation = params[:user_id].present? + +.ticket + = render 'tickets/edit_form' + = render 'tickets/comments' diff --git a/engines/support/app/views/tickets/show.html.haml b/engines/support/app/views/tickets/show.html.haml index 4f3c127..99afa2a 100644 --- a/engines/support/app/views/tickets/show.html.haml +++ b/engines/support/app/views/tickets/show.html.haml @@ -2,11 +2,4 @@ .ticket = render 'tickets/edit_form' - %table.table.table-striped.table-bordered - %tbody - = render :partial => 'tickets/comment', :collection => @ticket.comments - %tr - %td.user - = current_user.login || t(:anonymous) - %td.comment - = render 'tickets/new_comment_form' + = render 'tickets/comments' diff --git a/engines/support/config/routes.rb b/engines/support/config/routes.rb index 23e0c11..ca471b3 100644 --- a/engines/support/config/routes.rb +++ b/engines/support/config/routes.rb @@ -1,8 +1,16 @@ Rails.application.routes.draw do - scope "(:locale)", :locale => MATCH_LOCALE do - resources :tickets, :except => :edit + scope "(:locale)", locale: MATCH_LOCALE do + + resources :tickets, except: :edit do + member do + put 'open' + put 'close' + end + end + resources :users do - resources :tickets, :except => :edit + resources :tickets, except: :edit end + end end diff --git a/engines/support/test/functional/tickets_controller_test.rb b/engines/support/test/functional/tickets_controller_test.rb index e103d01..1d074cc 100644 --- a/engines/support/test/functional/tickets_controller_test.rb +++ b/engines/support/test/functional/tickets_controller_test.rb @@ -112,5 +112,22 @@ class TicketsControllerTest < ActionController::TestCase assert_not_nil assigns(:ticket).comments.first.posted_by assert_equal assigns(:ticket).comments.first.posted_by, @current_user.id end + + test "close ticket" do + login + open_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id + post :close, id: open_ticket.id + assert !open_ticket.reload.is_open + end + + test "reopen ticket" do + login + open_ticket = FactoryGirl.create :ticket_with_comment, + created_by: @current_user.id, is_open: false + post :open, id: open_ticket.id + assert open_ticket.reload.is_open + end + end -- cgit v1.2.3 From c10f9311678ff2183443bc03e153b30d3b68ff74 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 13:09:59 +0200 Subject: Controller#flash_for instead of FlashResponder FlashResponder added a flash before responding. However at the point of responding objects have already been saved. So there is no way to test if they were changed. Now instead we can call flash_for resource before resource.save and it will add the flash messages only if the resource was actually changed. --- app/controllers/controller_extension/flash.rb | 33 ++++++++++++++++++++++ config/initializers/add_controller_methods.rb | 1 + .../support/app/controllers/tickets_controller.rb | 8 ++---- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 app/controllers/controller_extension/flash.rb diff --git a/app/controllers/controller_extension/flash.rb b/app/controllers/controller_extension/flash.rb new file mode 100644 index 0000000..6a62351 --- /dev/null +++ b/app/controllers/controller_extension/flash.rb @@ -0,0 +1,33 @@ +module ControllerExtension::Flash + extend ActiveSupport::Concern + + protected + + def flash_for(resource, options = {}) + return unless resource.changed? + message = flash_message_for(resource) + type = flash_type(resource) + if message.present? + flash[type] = [message, flash[type]].join(' ') + end + end + + def flash_message_for(resource) + I18n.t flash_i18n_key(resource), + scope: :flash, + cascade: true, + resource: resource.class.model_name.human + end + + def flash_i18n_key(resource) + namespace = [action_name] + namespace += controller_path.split('/') + namespace << flash_type(resource) + namespace.join(".") + end + + def flash_type(resource) + resource.valid? ? :success : :error + end + +end diff --git a/config/initializers/add_controller_methods.rb b/config/initializers/add_controller_methods.rb index f572ecb..03e8393 100644 --- a/config/initializers/add_controller_methods.rb +++ b/config/initializers/add_controller_methods.rb @@ -1,4 +1,5 @@ ActiveSupport.on_load(:application_controller) do include ControllerExtension::Authentication include ControllerExtension::TokenAuthentication + include ControllerExtension::Flash end diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb index bb98277..7b6a7a0 100644 --- a/engines/support/app/controllers/tickets_controller.rb +++ b/engines/support/app/controllers/tickets_controller.rb @@ -23,10 +23,11 @@ class TicketsController < ApplicationController @ticket.comments.last.posted_by = current_user.id @ticket.comments.last.private = false unless admin? @ticket.created_by = current_user.id + flash_for @ticket if @ticket.save && !logged_in? flash[:success] = t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) end - respond_with(@ticket, :location => auto_ticket_path(@ticket)) + respond_with @ticket, :location => auto_ticket_path(@ticket) end def show @@ -61,6 +62,7 @@ class TicketsController < ApplicationController @ticket.comments.last.private = false unless admin? end + flash_for @ticket @ticket.save respond_with @ticket, location: redirection_path end @@ -82,10 +84,6 @@ class TicketsController < ApplicationController @title = t(:tickets) end - def self.responder - Responders::FlashResponder - end - private # -- cgit v1.2.3 From a337088f4d6d12d1ea26f494f4ca078cff4b4070 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 13:20:25 +0200 Subject: remove unused bold helper and instead sanitize flash --- app/controllers/application_controller.rb | 10 ---------- app/helpers/application_helper.rb | 3 ++- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 35d6cb4..a4560e2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,16 +23,6 @@ class ApplicationController < ActionController::Base json: {error: "The server failed to process your request. We'll look into it."} end - # - # Allows us to pass through bold text to flash messages. See format_flash() for where this is reversed. - # - # TODO: move to core - # - def bold(str) - "[b]#{str}[/b]" - end - helper_method :bold - ## ## LOCALE ## diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 90e649a..6de5e1b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -40,8 +40,9 @@ module ApplicationHelper end end + # fairly strict sanitation for flash messages def format_flash(msg) - html_escape(msg).gsub('[b]', '').gsub('[/b]', '').html_safe + sanitize(msg, tags: %w(em strong b br), attributes: []) end end -- cgit v1.2.3 From 560eb039f4778257559395583e1233d052d44127 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 May 2014 13:50:32 +0200 Subject: flash_for with_errors option displays error messages --- app/controllers/controller_extension/flash.rb | 18 ++++++++++++++---- engines/support/app/controllers/tickets_controller.rb | 2 +- engines/support/app/views/tickets/edit.html.haml | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/controller_extension/flash.rb b/app/controllers/controller_extension/flash.rb index 6a62351..8bc9ee7 100644 --- a/app/controllers/controller_extension/flash.rb +++ b/app/controllers/controller_extension/flash.rb @@ -5,10 +5,15 @@ module ControllerExtension::Flash def flash_for(resource, options = {}) return unless resource.changed? + add_flash_message_for resource + add_flash_errors_for resource if options[:with_errors] + end + + def add_flash_message_for(resource) message = flash_message_for(resource) - type = flash_type(resource) + type = flash_type_for(resource) if message.present? - flash[type] = [message, flash[type]].join(' ') + flash[type] = message end end @@ -22,12 +27,17 @@ module ControllerExtension::Flash def flash_i18n_key(resource) namespace = [action_name] namespace += controller_path.split('/') - namespace << flash_type(resource) + namespace << flash_type_for(resource) namespace.join(".") end - def flash_type(resource) + def flash_type_for(resource) resource.valid? ? :success : :error end + def add_flash_errors_for(resource) + return if resource.valid? + flash[:error] += "
" + flash[:error] += resource.errors.full_messages.join(".
") + end end diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb index 7b6a7a0..9c1a741 100644 --- a/engines/support/app/controllers/tickets_controller.rb +++ b/engines/support/app/controllers/tickets_controller.rb @@ -62,7 +62,7 @@ class TicketsController < ApplicationController @ticket.comments.last.private = false unless admin? end - flash_for @ticket + flash_for @ticket, with_errors: true @ticket.save respond_with @ticket, location: redirection_path end diff --git a/engines/support/app/views/tickets/edit.html.haml b/engines/support/app/views/tickets/edit.html.haml index 99afa2a..03bda7d 100644 --- a/engines/support/app/views/tickets/edit.html.haml +++ b/engines/support/app/views/tickets/edit.html.haml @@ -1,4 +1,5 @@ - @show_navigation = params[:user_id].present? +- @comment = TicketComment.new .ticket = render 'tickets/edit_form' -- cgit v1.2.3 From 19bce0f114180f355f0df367cf6d21bd957734a6 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 May 2014 14:57:29 +0200 Subject: tickets: structure i18n --- app/views/layouts/_header.html.haml | 2 +- app/views/layouts/_navigation.html.haml | 2 +- config/locales/flash.en.yml | 10 ++ .../support/app/controllers/tickets_controller.rb | 2 +- engines/support/app/helpers/tickets_helper.rb | 14 +-- engines/support/app/models/ticket_comment.rb | 5 + .../support/app/views/tickets/_comment.html.haml | 5 +- .../support/app/views/tickets/_edit_form.html.haml | 29 ++--- .../app/views/tickets/_new_comment_form.html.haml | 6 +- engines/support/app/views/tickets/_tabs.html.haml | 18 ++- engines/support/app/views/tickets/index.html.haml | 10 +- engines/support/app/views/tickets/new.html.haml | 2 +- engines/support/config/locales/en.yml | 124 +++++++++++++++++---- lib/extensions/couchrest.rb | 1 + 14 files changed, 155 insertions(+), 75 deletions(-) create mode 100644 config/locales/flash.en.yml diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index a1dd47a..fbc46b3 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -4,7 +4,7 @@ %li{:class => ("active" if controller?('users', 'overviews') || params[:user_id])} = link_to t(:users), users_path %li{:class => ("active" if controller?('tickets') && !params[:user_id])} - = link_to t(:tickets), tickets_path + = link_to t(".tickets", cascade: true), tickets_path %li = link_to t(:logout), logout_path, :method => :delete - if @user && @show_navigation diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index b81c43d..94f71f7 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -2,6 +2,6 @@ = link_to_navigation t(:overview), @user, :active => (controller?(:users) && action?(:show)) = link_to_navigation t(:account_settings), edit_user_path(@user), :active => (controller?(:users) && !action?(:show)) - # will want link for identity settings - = link_to_navigation t(:support_tickets), auto_tickets_path, :active => controller?(:tickets) + = link_to_navigation t(".tickets"), auto_tickets_path, :active => controller?(:tickets) = link_to_navigation t(:billing_settings), billing_top_link(@user), :active => controller?(:customer, :payments, :subscriptions, :credit_card_info) if APP_CONFIG[:billing] = link_to_navigation t(:logout), logout_path, :method => :delete diff --git a/config/locales/flash.en.yml b/config/locales/flash.en.yml new file mode 100644 index 0000000..7ad28f8 --- /dev/null +++ b/config/locales/flash.en.yml @@ -0,0 +1,10 @@ +en: + flash: + success: "%{resource} was successfully saved." + error: "%{resource} could not be saved." + create: + success: "%{resource} was successfully created." + error: "%{resource} could not be created." + update: + success: "%{resource} was successfully updated." + error: "%{resource} could not be updated." diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb index 9c1a741..857d071 100644 --- a/engines/support/app/controllers/tickets_controller.rb +++ b/engines/support/app/controllers/tickets_controller.rb @@ -81,7 +81,7 @@ class TicketsController < ApplicationController protected def set_title - @title = t(:tickets) + @title = t("layouts.title.tickets") end private diff --git a/engines/support/app/helpers/tickets_helper.rb b/engines/support/app/helpers/tickets_helper.rb index 7af50d6..11b02e4 100644 --- a/engines/support/app/helpers/tickets_helper.rb +++ b/engines/support/app/helpers/tickets_helper.rb @@ -35,13 +35,7 @@ module TicketsHelper # def link_to_status(new_status) - if new_status == "open" - label = t(:open_tickets) - elsif new_status == "closed" - label = t(:closed_tickets) - elsif new_status == "all" - label = t(:all_tickets) - end + label = t(:".#{new_status}", cascade: true) link_to label, auto_tickets_path(:open_status => new_status, :sort_order => search_order) end @@ -62,11 +56,7 @@ module TicketsHelper direction = 'desc' end - if order_field == 'updated' - label = t(:updated) - elsif order_field == 'created' - label = t(:created) - end + label = t(:".#{order_field}", cascade: true) link_to auto_tickets_path(:sort_order => order_field + '_at_' + direction, :open_status => search_status) do arrow + label diff --git a/engines/support/app/models/ticket_comment.rb b/engines/support/app/models/ticket_comment.rb index bed5237..2c5df41 100644 --- a/engines/support/app/models/ticket_comment.rb +++ b/engines/support/app/models/ticket_comment.rb @@ -18,6 +18,11 @@ class TicketComment # view :by_body #end + # translations are in the same scope as those of a "proper" couchrest model + def self.i18n_scope + "couchrest" + end + def is_comment_validated? !!posted_by end diff --git a/engines/support/app/views/tickets/_comment.html.haml b/engines/support/app/views/tickets/_comment.html.haml index 778ca13..65ec394 100644 --- a/engines/support/app/views/tickets/_comment.html.haml +++ b/engines/support/app/views/tickets/_comment.html.haml @@ -1,4 +1,5 @@ -- if admin? or !comment.private # only show comment if user is admin or comment is not private +- # only show comment if user is admin or comment is not private +- if admin? or !comment.private %tr %td.user %div @@ -17,4 +18,4 @@ %span.label.label-important = t(:private) %td.comment - = simple_format(comment.body) \ No newline at end of file + = simple_format(comment.body) diff --git a/engines/support/app/views/tickets/_edit_form.html.haml b/engines/support/app/views/tickets/_edit_form.html.haml index 22815f2..522489e 100644 --- a/engines/support/app/views/tickets/_edit_form.html.haml +++ b/engines/support/app/views/tickets/_edit_form.html.haml @@ -23,29 +23,24 @@ %p.first - if @ticket.is_open? %span.label.label-info - %b{style: 'padding:10px'}= t(:open) - = f.button :loading, t(:close), class: 'btn-mini' + %b{style: 'padding:10px'}= t("tickets.status.open") + = f.button :loading, t("tickets.action.close"), class: 'btn-mini' - else %span.label.label-success - %b{style: 'padding:10px'}= t(:closed) - = f.button :loading, t(:open), class: 'btn-mini' - %span.label.label-clear= t(:created_by_on, :user => created_by, :time => @ticket.created_at.to_s(:short)).html_safe + %b{style: 'padding:10px'}= t("tickets.status.closed") + = f.button :loading, t("tickets.action.open"), class: 'btn-mini' + %span.label.label-clear + = t("tickets.created_by_on", user: created_by, time: @ticket.created_at.to_s(:short), cascade: true).html_safe = simple_form_for @ticket do |f| = hidden_ticket_fields - %div= t(:subject) - = f.text_field :subject, :class => 'large full-width' + = f.input :subject, input_html: {:class => 'large full-width'} .row-fluid .span4 - %div= t(:status) - = f.select :is_open, [[t(:open), "true"], [t(:closed), "false"]] + = f.input :is_open, as: :select, collection: [:true, :false], include_blank: false .span4 - %div= t(:email) - = f.text_field :email + = f.input :email .span4 - %div - = t(:regarding_account) - = regarding_user_link - = f.text_field :regarding_user - = f.button :loading, t(:save), :value => 'save' + = f.input :regarding_user, label: Ticket.human_attribute_name(:regarding_user) + regarding_user_link + = f.button :loading - if admin? - = link_to t(:destroy), auto_ticket_path(@ticket), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn' + = link_to t(".destroy", cascade: true), auto_ticket_path(@ticket), :confirm => t("tickets.confirm.destroy.are_you_sure", cascade: true), :method => :delete, :class => 'btn' diff --git a/engines/support/app/views/tickets/_new_comment_form.html.haml b/engines/support/app/views/tickets/_new_comment_form.html.haml index 40c737f..b829b6b 100644 --- a/engines/support/app/views/tickets/_new_comment_form.html.haml +++ b/engines/support/app/views/tickets/_new_comment_form.html.haml @@ -7,7 +7,7 @@ = c.input :body, :label => false, :as => :text, :input_html => {:class => "full-width", :rows=> 5} - if admin? = c.input :private, :as => :boolean, :label => false, :inline_label => true - = f.button :loading, t(:post_reply), class: 'btn-primary', value: 'post_reply' + = f.button :loading, t(".post_reply"), class: 'btn-primary', value: 'post_reply' - if logged_in? && @ticket.is_open - = f.button :loading, t(:reply_and_close), value: 'reply_and_close' - = link_to t(:cancel), auto_tickets_path, :class => :btn + = f.button :loading, t(".reply_and_close"), value: 'reply_and_close' + = link_to t(".cancel"), auto_tickets_path, :class => :btn diff --git a/engines/support/app/views/tickets/_tabs.html.haml b/engines/support/app/views/tickets/_tabs.html.haml index 445a909..7872bb5 100644 --- a/engines/support/app/views/tickets/_tabs.html.haml +++ b/engines/support/app/views/tickets/_tabs.html.haml @@ -3,21 +3,17 @@ -# - unless action?(:new) or action?(:create) %ul.nav.nav-pills.pull-right.slim - %li{:class=> ("active" if search_order.start_with? 'created_at')} - = link_to_order('created') - %li{:class=> ("active" if search_order.start_with? 'updated_at')} - = link_to_order('updated') + - %w(created updated).each do |order| + %li{:class=> ("active" if search_order.start_with? order)} + = link_to_order(order) -# -# STATUS FILTER TABS -# %ul.nav.nav-tabs - if logged_in? - %li{:class => ("active" if search_status == 'open')} - = link_to_status 'open' - %li{:class => ("active" if search_status == 'closed')} - = link_to_status 'closed' - %li{:class => ("active" if search_status == 'all')} - = link_to_status 'all' + - %w(open closed all).each do |status| + %li{:class => ("active" if search_status == status)} + = link_to_status status %li{:class => ("active" if action?(:new) || action?(:create))} - = link_to icon(:plus, :black) + t(:new_ticket), auto_new_ticket_path + = link_to icon(:plus, :black) + t(".new", cascade: true), auto_new_ticket_path diff --git a/engines/support/app/views/tickets/index.html.haml b/engines/support/app/views/tickets/index.html.haml index a4df6e3..526cd6d 100644 --- a/engines/support/app/views/tickets/index.html.haml +++ b/engines/support/app/views/tickets/index.html.haml @@ -5,15 +5,15 @@ %table.table.table-striped.table-bordered %thead %tr - %th= t(:subject) - %th= t(:created) - %th= t(:updated) - %th= t(:voices) + %th= t(".subject") + %th= t(".created") + %th= t(".updated") + %th= t(".voices") %tbody - if @tickets.any? = render @tickets.all - else %tr - %td{:colspan=>4}= t(:none) + %td{:colspan=>4}= t(".none") = paginate @tickets diff --git a/engines/support/app/views/tickets/new.html.haml b/engines/support/app/views/tickets/new.html.haml index 3de5fe9..d3580f9 100644 --- a/engines/support/app/views/tickets/new.html.haml +++ b/engines/support/app/views/tickets/new.html.haml @@ -11,7 +11,7 @@ = 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} + = c.input :body, :as => :text, :input_html => {:class => "full-width", :rows=> 5} - if admin? = c.input :private, :as => :boolean, :label => false, :inline_label => true = f.button :wrapped, cancel: (logged_in? ? auto_tickets_path : home_path) diff --git a/engines/support/config/locales/en.yml b/engines/support/config/locales/en.yml index 342adea..f2caecc 100644 --- a/engines/support/config/locales/en.yml +++ b/engines/support/config/locales/en.yml @@ -1,22 +1,104 @@ en: - access_ticket_text: > - You can later access this ticket at the URL %{full_url}. You might want to bookmark this page to find it again. - Anybody with this URL will be able to access this ticket, so if you are on a shared computer you might want to - remove it from the browser history. - support_tickets: "Support Tickets" - all_tickets: "All Tickets" - my_tickets: "My Tickets" - open_tickets: "Open Tickets" - closed_tickets: "Closed Tickets" - new_ticket: "New Ticket" - tickets: "Tickets" - subject: "Subject" - destroy: "Destroy" - open: "Open" - closed: "Closed" - close: "Close" - post_reply: "Post Reply" - reply_and_close: "Reply and Close" - description: "Description" - ticket: "Ticket" - regarding_account: "Regarding Account" \ No newline at end of file + # translations used in the layout views or @title + layouts: + # fallback for all translations of "tickets" nested below: + tickets: "Tickets" + title: + tickets: "Tickets" + header: + tickets: "Tickets" + navigation: + tickets: "Support Tickets" + # Translations used in the views inside the tickets directory + tickets: + # If these do not exist they will be looked up in the global scope. + all: "All Tickets" + open: "Open Tickets" + closed: "Closed Tickets" + new: "New Ticket" + created: "Created at" + updated: "Updated at" + subject: "couchrest.models.tickets.attributes.subject" + status: + open: "Open" + closed: "Closed" + action: + open: "Open" + close: "Close" + confirm: + destroy: + are_you_sure: "Are you sure you want to destroy this ticket?" + # If you want to be more specific you can use the partial as a scope: + tabs: + all: "All Tickets" + open: "Open Tickets" + closed: "Closed Tickets" + index: + none: "No tickets have been found." + voices: "Voices" + destroy: "Destroy" + post_reply: "Post Reply" + reply_and_close: "Reply and Close" + access_ticket_text: > + You can later access this ticket at the URL %{full_url}. You might want to bookmark this page to find it again. + Anybody with this URL will be able to access this ticket, so if you are on a shared computer you might want to + remove it from the browser history. + # rails i18n + helpers: + # translations used for submit buttons. simple form picks these up + submit: + ticket: + create: "Submit Ticket" + update: "Update Ticket" + # translations for the model and its attributes + # serve as fallback for simpleform labels + couchrest: + models: + ticket: "Ticket" + ticket_comment: "Comment" + attributes: + ticket: + # these will fallback to translations in the "attributes" scope + subject: "Subject" + email: "Email" + regarding_user: "Regarding User" + regarding_account: "Regarding Account" + is_open: "Status" + ticket_comment: + body: "Description" + private: "private" + simple_form: + # labels next to the field + labels: + # these will fallback to the human_name translations of the model + ticket: + # these will fallback to translations in "simple_form.labels.defaults" + regarding_: + # you can be specific about translations for a given action: + #edit: + # regaring_user: + email: "Email" + comments: + # these will fall back to "simple_form.labels.comments" + body: "Description" + # comments: ~ + options: + ticket: + is_open: + "true": "Open" + "false": "Closed" + # mouse over hints for the given fields + hints: + ticket: + email: "Please provide an email address so we can get back to you." + # these will fallback to translations in "simple_form.hints.defaults" + # placeholders inside the fields before anything was typed + #placeholders: + # ticket: ~ + # these will fallback to translations in "simple_form.placeholders.defaults" + + # these are generic defaults. They should be moved into the toplevel + # attributes: + #simple_form: + #labels: + # defaults: diff --git a/lib/extensions/couchrest.rb b/lib/extensions/couchrest.rb index 0e5051a..df83c9f 100644 --- a/lib/extensions/couchrest.rb +++ b/lib/extensions/couchrest.rb @@ -2,6 +2,7 @@ module CouchRest module Model class Base extend ActiveModel::Naming + extend ActiveModel::Translation end module Designs -- cgit v1.2.3 From 4085e3fabef6427cd3f8be9b61c209bd82eaa595 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 24 May 2014 10:33:31 +0200 Subject: navigation works with empty locale selected Just in case some translation keys are not present things should still work and make sense. So translation keys should be picked in a meaningful way and scoped rather than prefixed. For example overview.account will turn into "Account" if no translation is present while "overview_account" will turn into "Overview Account". We usually want the former. --- app/views/common/_action_buttons.html.haml | 8 +++---- app/views/common/_download_button.html.haml | 2 +- app/views/users/_overview.html.haml | 24 +++++++++++++++++++ app/views/users/new.html.haml | 2 +- app/views/users/show.html.haml | 37 ++++++----------------------- config/locales/en.yml | 33 +------------------------ config/locales/footer.en.yml | 7 ++++++ config/locales/generic.en.yml | 4 ++++ config/locales/home.en.yml | 7 ++++++ config/locales/users.en.yml | 15 ++++++------ engines/support/config/locales/en.yml | 1 + 11 files changed, 64 insertions(+), 76 deletions(-) create mode 100644 app/views/users/_overview.html.haml create mode 100644 config/locales/footer.en.yml create mode 100644 config/locales/generic.en.yml create mode 100644 config/locales/home.en.yml diff --git a/app/views/common/_action_buttons.html.haml b/app/views/common/_action_buttons.html.haml index c74fcd1..d00cf74 100644 --- a/app/views/common/_action_buttons.html.haml +++ b/app/views/common/_action_buttons.html.haml @@ -2,10 +2,10 @@ .row-fluid.second .login.span4 %span.link= link_to(icon('ok-sign', icon_color) + t(:login), login_path, :class => 'btn') - %span.info= t(:login_info) + %span.info= t(:login_info, default: "") .signup.span4 %span.link= link_to(icon('user', icon_color) + t(:signup), signup_path, :class => 'btn') - %span.info= t(:signup_info) + %span.info= t(:signup_info, default: "") .help.span4 - %span.link= link_to(icon('question-sign', icon_color) + t(:get_help), new_ticket_path, :class => 'btn') - %span.info= t(:help_info) + %span.link= link_to(icon('question-sign', icon_color) + t(:support_tickets), new_ticket_path, :class => 'btn') + %span.info= t(:support_info, default: "") diff --git a/app/views/common/_download_button.html.haml b/app/views/common/_download_button.html.haml index e57c56b..d6d7bde 100644 --- a/app/views/common/_download_button.html.haml +++ b/app/views/common/_download_button.html.haml @@ -4,5 +4,5 @@ .download.span8 = link_to client_download_url, class: "btn btn-large btn-primary" do = big_icon('download') - = t(:download_client) + = t(:download_bitmask) .span2 diff --git a/app/views/users/_overview.html.haml b/app/views/users/_overview.html.haml new file mode 100644 index 0000000..e38fdc8 --- /dev/null +++ b/app/views/users/_overview.html.haml @@ -0,0 +1,24 @@ +.overview + + %h2.first= t(".welcome", username: @user.login, cascade: true) + + - if admin? + %p + = t(:created) + = @user.created_at + %br + = t(:updated) + = @user.updated_at + %br + = t(:enabled) + = @user.enabled? + + %p= t(:overview_intro, default: "") + + %ul.unstyled + %li= icon('user') + link_to(t(".account"), edit_user_path(@user)) + - # %li= icon('envelope') + link_to(t(:overview_email), {insert path for user identities, presuambly} + %li= icon('question-sign') + link_to(t(".tickets"), user_tickets_path(@user)) + %li= icon('shopping-cart') + link_to(t(".billing"), billing_top_link(@user)) if APP_CONFIG[:billing] + + diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml index bc36068..41a9d55 100644 --- a/app/views/users/new.html.haml +++ b/app/views/users/new.html.haml @@ -17,5 +17,5 @@ = f.input :login, :label => t(:username), :required => false, :input_html => { :id => :srp_username } = f.input :password, :required => false, :validate => true, :input_html => { :id => :srp_password } = f.input :password_confirmation, :required => false, :validate => true, :input_html => { :id => :srp_password_confirmation } - = f.button :wrapped, value: t(:signup), cancel: home_path + = f.button :wrapped, cancel: home_path diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index ddc33ab..6760099 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,30 +1,7 @@ -.overview - - %h2.first= t(:overview_welcome, :username => @user.login) - - - if admin? - %p - = t(:created) - = @user.created_at - %br - = t(:updated) - = @user.updated_at - %br - = t(:enabled) - = @user.enabled? - - %p= t(:overview_intro) - - %ul.unstyled - %li= icon('user') + link_to(t(:overview_account), edit_user_path(@user)) - - # %li= icon('envelope') + link_to(t(:overview_email), {insert path for user identities, presuambly} - %li= icon('question-sign') + link_to(t(:overview_tickets), user_tickets_path(@user)) - %li= icon('shopping-cart') + link_to(t(:overview_billing), billing_top_link(@user)) if APP_CONFIG[:billing] - - - .container-fluid - .row-fluid - %h4 To use bitmask services: - = link_to client_download_url, class: "btn btn-primary" do - %i.icon-arrow-down.icon-white - = t(:download_client) += render 'overview' +.container-fluid + .row-fluid + %h4 To use bitmask services: + = link_to client_download_url, class: "btn btn-primary" do + %i.icon-arrow-down.icon-white + = t(:download_bitmask) diff --git a/config/locales/en.yml b/config/locales/en.yml index a7a76a8..feac53b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,17 +1,7 @@ en: - flash: - success: "%{resource} was successfully saved." - create: - success: "%{resource} was successfully created." - update: - success: "%{resource} was successfully updated." home: Home - privacy_policy: Privacy Policy - terms_of_service: Terms of Service - pricing: Pricing - about: About Us - contact: Contact + example_email: 'user@domain.org' not_found_title: Page not found. not_found_subtitle: "The page you were looking for doesn't exist." not_found_lead: "You may have mistyped the address or the page may have moved." @@ -19,8 +9,6 @@ en: server_error_subtitle: We ran into a server error. server_error_lead: The problem has been logged and we will look into it. no_such_thing: "No such %{thing}." - - thing_was_successfully_created: "%{thing} was successfully created." create_thing: "Create %{thing}" overview: "Overview" @@ -40,22 +28,3 @@ en: changes_saved: "Changes saved successfully." are_you_sure: "Are you sure? This change cannot be undone." - download_client: "Download Bitmask" - client_info: "The Bitmask application allows you to use %{provider} services." - all_downloads_info: "It is available for %{clients}." - other_downloads_info: "Bitmask is also available for %{clients}." - login_info: "Log in to change your account settings, create support tickets, and manage payments." - signup_info: "Get a user account via this website. We recommend registering via the Bitmask application instead unless you are only using Bitmask for Android." - welcome: "Welcome to %{provider}." - get_help: "Get Help" - help_info: "Can't login? Create a new support ticket anonymously." - example_email: 'user@domain.org' - os: - linux32: "Linux (32 bit)" - linux64: "Linux (64 bit)" - linux: "GNU/Linux" - windows: "Windows" - android: "Android" - osx: "Mac OS" - other: "(not available for your OS)" - diff --git a/config/locales/footer.en.yml b/config/locales/footer.en.yml new file mode 100644 index 0000000..65f8ab2 --- /dev/null +++ b/config/locales/footer.en.yml @@ -0,0 +1,7 @@ +en: + # layout/footer + privacy_policy: Privacy Policy + terms_of_service: Terms of Service + pricing: Pricing + about: About Us + contact: Contact diff --git a/config/locales/generic.en.yml b/config/locales/generic.en.yml new file mode 100644 index 0000000..dce6d93 --- /dev/null +++ b/config/locales/generic.en.yml @@ -0,0 +1,4 @@ +en: + signup: "Sign Up" + login: "Log In" + cancel: "Cancel" diff --git a/config/locales/home.en.yml b/config/locales/home.en.yml new file mode 100644 index 0000000..4fdbfc2 --- /dev/null +++ b/config/locales/home.en.yml @@ -0,0 +1,7 @@ +en: + welcome: "Welcome to %{provider}." + download_bitmask: "Download Bitmask" + + login_info: "Log in to change your account settings, create support tickets, and manage payments." + signup_info: "Get a user account via this website. We recommend registering via the Bitmask application instead unless you are only using Bitmask for Android." + support_info: "Can't login? Create a new support ticket anonymously." diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index 0ca5a73..3f4fbed 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -2,9 +2,6 @@ en: account_settings: "Account Settings" logout: "Logout" none: "None" - signup: "Sign Up" - cancel: "Cancel" - login: "Log In" username: "Username" password: "Password" change_password: "Change Password" @@ -42,11 +39,13 @@ en: # # overview # - overview_welcome: "Welcome %{username}." - overview_intro: "From this user control panel, you can:" - overview_tickets: "Create and check support tickets." - overview_email: "Modify email settings." - overview_account: "Destroy your account." + users: + overview: + welcome: "Welcome %{username}." + intro: "From this user control panel, you can:" + tickets: "Create and check support tickets." + email: "Modify email settings." + account: "Destroy your account." # # rails diff --git a/engines/support/config/locales/en.yml b/engines/support/config/locales/en.yml index f2caecc..8d2af67 100644 --- a/engines/support/config/locales/en.yml +++ b/engines/support/config/locales/en.yml @@ -1,4 +1,5 @@ en: + support_tickets: "Support" # translations used in the layout views or @title layouts: # fallback for all translations of "tickets" nested below: -- cgit v1.2.3 From bbeb4b629dc38d82b3b3200706dd25b8def8892e Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 24 May 2014 13:39:10 +0200 Subject: sorting translation keys some --- app/views/errors/not_found.html.haml | 6 +++--- app/views/errors/server_error.html.haml | 6 +++--- config/locales/en.yml | 30 ------------------------------ config/locales/errors.en.yml | 11 +++++++++++ config/locales/generic.en.yml | 21 +++++++++++++++++++++ config/locales/home.en.yml | 1 + config/locales/simple_form.en.yml | 4 ++-- config/locales/users.en.yml | 4 ++-- test/integration/browser/account_test.rb | 6 +++--- test/integration/browser/session_test.rb | 2 +- 10 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 config/locales/en.yml create mode 100644 config/locales/errors.en.yml diff --git a/app/views/errors/not_found.html.haml b/app/views/errors/not_found.html.haml index 75cb889..c7fec22 100644 --- a/app/views/errors/not_found.html.haml +++ b/app/views/errors/not_found.html.haml @@ -1,7 +1,7 @@ .hero-unit - %h1=t :not_found_title - %h2=t :not_found_subtitle - %p.lead=t :not_found_lead + %h1=t 'errors.title.page_not_found' + %h2=t 'errors.subtitle.page_not_found', default: '' + %p.lead=t 'errors.text.page_not_found', default: '' %a.btn.btn-primary.btn-large{href:'/'} %i.icon-home.icon-white =t :home diff --git a/app/views/errors/server_error.html.haml b/app/views/errors/server_error.html.haml index 68baf20..a4133da 100644 --- a/app/views/errors/server_error.html.haml +++ b/app/views/errors/server_error.html.haml @@ -1,7 +1,7 @@ .hero-unit - %h1=t :server_error_title - %h2=t :server_error_subtitle - %p.lead=t :server_error_lead + %h1=t 'errors.title.server_error' + %h2=t 'errors.subtitle.server_error', default: '' + %p.lead=t 'errors.text.server_error', default: '' %a.btn.btn-primary.btn-large{href:'/'} %i.icon-home.icon-white =t :home diff --git a/config/locales/en.yml b/config/locales/en.yml deleted file mode 100644 index feac53b..0000000 --- a/config/locales/en.yml +++ /dev/null @@ -1,30 +0,0 @@ -en: - home: Home - - example_email: 'user@domain.org' - not_found_title: Page not found. - not_found_subtitle: "The page you were looking for doesn't exist." - not_found_lead: "You may have mistyped the address or the page may have moved." - server_error_title: Ouch! - server_error_subtitle: We ran into a server error. - server_error_lead: The problem has been logged and we will look into it. - no_such_thing: "No such %{thing}." - create_thing: "Create %{thing}" - - overview: "Overview" - user_control_panel: "user control panel" - - created: "Created" - created_by_on: "Created by %{user} on %{time}" - updated: "Updated" - - none: "None" - unknown: "Unknown" - admin: "Admin" - anonymous: "Anonymous" - save: "Save" - add: "Add" - remove: "Remove" - changes_saved: "Changes saved successfully." - are_you_sure: "Are you sure? This change cannot be undone." - diff --git a/config/locales/errors.en.yml b/config/locales/errors.en.yml new file mode 100644 index 0000000..93feab1 --- /dev/null +++ b/config/locales/errors.en.yml @@ -0,0 +1,11 @@ +en: + errors: + title: + not_found: Page not found. + server_error: Ouch! + subtitle: + not_found: "The page you were looking for doesn't exist." + server_error: We ran into a server error. + text: + not_found: "You may have mistyped the address or the page may have moved." + server_error: The problem has been logged and we will look into it. diff --git a/config/locales/generic.en.yml b/config/locales/generic.en.yml index dce6d93..14dafac 100644 --- a/config/locales/generic.en.yml +++ b/config/locales/generic.en.yml @@ -1,4 +1,25 @@ en: signup: "Sign Up" login: "Log In" + logout: "Log Out" + cancel: "Cancel" + + created: "Created" + created_by_on: "Created by %{user} on %{time}" + updated: "Updated" + + none: "None" + unknown: "Unknown" + admin: "Admin" + anonymous: "Anonymous" + save: "Save" + add: "Add" + remove: "Remove" + changes_saved: "Changes saved successfully." + are_you_sure: "Are you sure? This change cannot be undone." + + example_email: 'user@domain.org' + + no_such_thing: "No such %{thing}." + create_thing: "Create %{thing}" diff --git a/config/locales/home.en.yml b/config/locales/home.en.yml index 4fdbfc2..c3cdfb1 100644 --- a/config/locales/home.en.yml +++ b/config/locales/home.en.yml @@ -1,4 +1,5 @@ en: + home: Home welcome: "Welcome to %{provider}." download_bitmask: "Download Bitmask" diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 5d0c675..4b35883 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -29,8 +29,8 @@ en: helpers: submit: user: - create: "Sign up" + create: "Sign Up" update: "Save" session: - create: "Log in" + create: "Log In" diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index 3f4fbed..0375174 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -1,7 +1,7 @@ en: + overview: "Overview" + user_control_panel: "user control panel" account_settings: "Account Settings" - logout: "Logout" - none: "None" username: "Username" password: "Password" change_password: "Change Password" diff --git a/test/integration/browser/account_test.rb b/test/integration/browser/account_test.rb index 491a9e1..8dc3043 100644 --- a/test/integration/browser/account_test.rb +++ b/test/integration/browser/account_test.rb @@ -9,7 +9,7 @@ class AccountTest < BrowserIntegrationTest test "signup successfully" do username, password = submit_signup assert page.has_content?("Welcome #{username}") - click_on 'Logout' + click_on 'Log Out' assert page.has_content?("Log In") assert_equal '/', current_path assert user = User.find_by_login(username) @@ -24,7 +24,7 @@ class AccountTest < BrowserIntegrationTest test "successful login" do username, password = submit_signup - click_on 'Logout' + click_on 'Log Out' attempt_login(username, password) assert page.has_content?("Welcome #{username}") within('.sidenav li.active') do @@ -83,7 +83,7 @@ class AccountTest < BrowserIntegrationTest fill_in 'Password confirmation', with: "other password" click_on 'Save' end - click_on 'Logout' + click_on 'Log Out' attempt_login(@user.login, "other password") assert page.has_content?("Welcome #{@user.login}") end diff --git a/test/integration/browser/session_test.rb b/test/integration/browser/session_test.rb index fb20847..d52508a 100644 --- a/test/integration/browser/session_test.rb +++ b/test/integration/browser/session_test.rb @@ -4,7 +4,7 @@ class SessionTest < BrowserIntegrationTest test "valid session" do login - assert page.has_content?("Logout") + assert page.has_content?("Log Out") end test "expired session" do -- cgit v1.2.3 From 863863ff1fb6c9ab13b44248417ae1c5e57987af Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 27 May 2014 10:14:40 +0200 Subject: remove icon_color variable - yagni --- app/views/common/_action_buttons.html.haml | 6 +++--- app/views/common/_home_page_buttons.html.haml | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/views/common/_action_buttons.html.haml b/app/views/common/_action_buttons.html.haml index d00cf74..398d384 100644 --- a/app/views/common/_action_buttons.html.haml +++ b/app/views/common/_action_buttons.html.haml @@ -1,11 +1,11 @@ .home-buttons .row-fluid.second .login.span4 - %span.link= link_to(icon('ok-sign', icon_color) + t(:login), login_path, :class => 'btn') + %span.link= link_to icon('ok-sign') + t(:login), login_path, :class => 'btn' %span.info= t(:login_info, default: "") .signup.span4 - %span.link= link_to(icon('user', icon_color) + t(:signup), signup_path, :class => 'btn') + %span.link= link_to icon('user') + t(:signup), signup_path, :class => 'btn' %span.info= t(:signup_info, default: "") .help.span4 - %span.link= link_to(icon('question-sign', icon_color) + t(:support_tickets), new_ticket_path, :class => 'btn') + %span.link= link_to icon('question-sign') + t(:get_help), new_ticket_path, :class => 'btn' %span.info= t(:support_info, default: "") diff --git a/app/views/common/_home_page_buttons.html.haml b/app/views/common/_home_page_buttons.html.haml index 8c47983..fc6348e 100644 --- a/app/views/common/_home_page_buttons.html.haml +++ b/app/views/common/_home_page_buttons.html.haml @@ -1,8 +1,6 @@ -- icon_color = :black - = render 'common/download_button' - if local_assigns[:divider] .row-fluid .span12 = render local_assigns[:divider] -= render 'common/action_buttons', icon_color: icon_color += render 'common/action_buttons' -- cgit v1.2.3 From cc59ce53e52bf48d97de16d66012e8309bf98fe8 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 27 May 2014 16:32:50 +0200 Subject: add btn helper for link_to with .btn Also translates the first arg if it's a symbol and adds more btn- classes if given as html_options[:type] --- app/views/common/_action_buttons.html.haml | 6 +++--- app/views/common/_download_button.html.haml | 2 +- app/views/pages/pricing.html.haml | 2 +- app/views/users/_destroy_account.html.haml | 6 +++--- app/views/users/show.html.haml | 2 +- engines/billing/app/views/credit_card_info/edit.html.haml | 3 +-- engines/billing/app/views/customer/_customer_data.html.haml | 2 +- engines/billing/app/views/customer/confirm.html.haml | 2 +- engines/billing/app/views/customer/edit.html.haml | 4 ++-- engines/billing/app/views/customer/show.html.haml | 6 +++--- engines/billing/app/views/subscriptions/destroy.html.haml | 2 +- engines/billing/app/views/subscriptions/index.html.haml | 2 +- engines/billing/app/views/subscriptions/show.html.haml | 3 ++- engines/support/app/views/tickets/_edit_form.html.haml | 2 +- engines/support/app/views/tickets/_new_comment_form.html.haml | 2 +- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/views/common/_action_buttons.html.haml b/app/views/common/_action_buttons.html.haml index 398d384..266abe1 100644 --- a/app/views/common/_action_buttons.html.haml +++ b/app/views/common/_action_buttons.html.haml @@ -1,11 +1,11 @@ .home-buttons .row-fluid.second .login.span4 - %span.link= link_to icon('ok-sign') + t(:login), login_path, :class => 'btn' + %span.link= btn icon('ok-sign') + t(:login), login_path %span.info= t(:login_info, default: "") .signup.span4 - %span.link= link_to icon('user') + t(:signup), signup_path, :class => 'btn' + %span.link= btn icon('user') + t(:signup), signup_path %span.info= t(:signup_info, default: "") .help.span4 - %span.link= link_to icon('question-sign') + t(:get_help), new_ticket_path, :class => 'btn' + %span.link= btn icon('question-sign') + t(:get_help), new_ticket_path %span.info= t(:support_info, default: "") diff --git a/app/views/common/_download_button.html.haml b/app/views/common/_download_button.html.haml index d6d7bde..9c26860 100644 --- a/app/views/common/_download_button.html.haml +++ b/app/views/common/_download_button.html.haml @@ -2,7 +2,7 @@ .row-fluid.first .span2 .download.span8 - = link_to client_download_url, class: "btn btn-large btn-primary" do + = btn client_download_url, type: [:large, :primary] do = big_icon('download') = t(:download_bitmask) .span2 diff --git a/app/views/pages/pricing.html.haml b/app/views/pages/pricing.html.haml index e339d27..983501e 100644 --- a/app/views/pages/pricing.html.haml +++ b/app/views/pages/pricing.html.haml @@ -1,5 +1,5 @@ %h1= t(:pricing) -%p= link_to(icon('user') + t(:signup), signup_path, :class => 'btn') +%p= btn icon('user') + t(:signup), signup_path - levels = APP_CONFIG[:service_levels] - if levels diff --git a/app/views/users/_destroy_account.html.haml b/app/views/users/_destroy_account.html.haml index 445f3c4..be003ce 100644 --- a/app/views/users/_destroy_account.html.haml +++ b/app/views/users/_destroy_account.html.haml @@ -8,20 +8,20 @@ - else = t(:admin_destroy_account, :username => @user.login) %p= t(:destroy_account_info) -= link_to user_path(@user), :method => :delete, :confirm => t(:are_you_sure), :class => "btn btn-danger" do += btn user_path(@user), :method => :delete, :confirm => t(:are_you_sure), :type => "danger" do %i.icon-remove.icon-white = t(:destroy_my_account) - if @user != current_user and @user.enabled? %legend = t(:deactivate_account, :username => @user.login) %p= t(:deactivate_description) - = link_to deactivate_user_path(@user), :method => :post, :class => "btn btn-warning" do + = btn deactivate_user_path(@user), :method => :post, :type => "warning" do %i.icon-pause.icon-white = t(:deactivate) - elsif @user != current_user and !@user.enabled? %legend = t(:enable_account, :username => @user.login) %p= t(:enable_description) - = link_to enable_user_path(@user), :method => :post, :class => "btn btn-warning" do + = btn enable_user_path(@user), :method => :post, :type => "warning" do %i.icon-ok.icon-white = t(:enable) diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 6760099..da8e467 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -2,6 +2,6 @@ .container-fluid .row-fluid %h4 To use bitmask services: - = link_to client_download_url, class: "btn btn-primary" do + = btn client_download_url, type: "primary" do %i.icon-arrow-down.icon-white = t(:download_bitmask) diff --git a/engines/billing/app/views/credit_card_info/edit.html.haml b/engines/billing/app/views/credit_card_info/edit.html.haml index bd86a4c..9e44344 100644 --- a/engines/billing/app/views/credit_card_info/edit.html.haml +++ b/engines/billing/app/views/credit_card_info/edit.html.haml @@ -13,5 +13,4 @@ %dt= f.label :cvv, 'CVV' %dd= f.text_field :cvv = hidden_field_tag :tr_data, @tr_data - = f.submit 'Save Payment Info', :class => :btn - = link_to t(:cancel), edit_customer_path(@user.id), :class => :btn + = f.button :wrapped, 'Save Payment Info', cancel: edit_customer_path(@user.id) diff --git a/engines/billing/app/views/customer/_customer_data.html.haml b/engines/billing/app/views/customer/_customer_data.html.haml index e9df040..439ae5c 100644 --- a/engines/billing/app/views/customer/_customer_data.html.haml +++ b/engines/billing/app/views/customer/_customer_data.html.haml @@ -13,4 +13,4 @@ %dt Expiration Date %dd= @default_cc.expiration_date - if current_user == @user - = link_to t(:edit_saved_data), edit_customer_path(@user.id), :class => :btn + = btn t(:edit_saved_data), edit_customer_path(@user.id) diff --git a/engines/billing/app/views/customer/confirm.html.haml b/engines/billing/app/views/customer/confirm.html.haml index 877a8ac..eab9616 100644 --- a/engines/billing/app/views/customer/confirm.html.haml +++ b/engines/billing/app/views/customer/confirm.html.haml @@ -11,4 +11,4 @@ - @result.customer.credit_cards.each do |cc| %dd= cc.masked_number - customer = Customer.find_by_user_id(@user.id) -= link_to 'View Customer Info', show_customer_path(@user.id), :class=> :btn \ No newline at end of file += btn 'View Customer Info', show_customer_path(@user.id) diff --git a/engines/billing/app/views/customer/edit.html.haml b/engines/billing/app/views/customer/edit.html.haml index e882d53..f461fcc 100644 --- a/engines/billing/app/views/customer/edit.html.haml +++ b/engines/billing/app/views/customer/edit.html.haml @@ -16,8 +16,8 @@ %dt= t(:stored_credit_card) %dd = @default_cc.masked_number - = link_to t(:change_credit_card), edit_credit_card_info_path(:id => @default_cc.token), :class => :btn + = btn t(:change_credit_card), edit_credit_card_info_path(:id => @default_cc.token) = hidden_field_tag :tr_data, @tr_data .form-actions = f.submit t(:save_customer_info), :class => 'btn btn-primary' - = link_to t(:cancel), show_customer_path(@user), :class=> :btn + = btn t(:cancel), show_customer_path(@user) diff --git a/engines/billing/app/views/customer/show.html.haml b/engines/billing/app/views/customer/show.html.haml index ec1779c..ce4d01a 100644 --- a/engines/billing/app/views/customer/show.html.haml +++ b/engines/billing/app/views/customer/show.html.haml @@ -9,7 +9,7 @@ - break if counter > 2 # not ruby-like, but object is a Braintree::ResourceCollection so limited methods available = render :partial => "payments/transaction_details", :locals => {:transaction => t} - counter += 1 - = link_to t(:transaction_history), user_payments_path(@user) + = btn :transaction_history, user_payments_path(@user) %legend= t(:subscriptions) - if @active_subscription = render :partial => "subscriptions/subscription_details", :locals => {:subscription => @active_subscription} @@ -19,9 +19,9 @@ - if current_user == @user %p .form-actions - = link_to t(:subscribe_to_plan), new_subscription_path, :class => :btn + = btn :subscribe_to_plan, new_subscription_path %p = link_to t(:all_subscriptions), user_subscriptions_path(@user) .form-actions - = link_to t(:make_donation), new_payment_path, :class => 'btn btn-primary' + = btn :make_donation, new_payment_path, :type => 'primary' diff --git a/engines/billing/app/views/subscriptions/destroy.html.haml b/engines/billing/app/views/subscriptions/destroy.html.haml index 44b4333..e6e8578 100644 --- a/engines/billing/app/views/subscriptions/destroy.html.haml +++ b/engines/billing/app/views/subscriptions/destroy.html.haml @@ -4,4 +4,4 @@ Error: = @result.message %p - = link_to 'Customer Information', show_customer_path(@user), :class=> :btn \ No newline at end of file + = btn 'Customer Information', show_customer_path(@user) diff --git a/engines/billing/app/views/subscriptions/index.html.haml b/engines/billing/app/views/subscriptions/index.html.haml index 3d4e8fd..1e3fb25 100644 --- a/engines/billing/app/views/subscriptions/index.html.haml +++ b/engines/billing/app/views/subscriptions/index.html.haml @@ -5,4 +5,4 @@ - pending_active_pastdue = true = render :partial => "subscription_details", :locals => {:subscription => s} - if !pending_active_pastdue and @user == current_user - = link_to 'subscribe to plan', new_subscription_path, :class => :btn \ No newline at end of file + = btn 'subscribe to plan', new_subscription_path diff --git a/engines/billing/app/views/subscriptions/show.html.haml b/engines/billing/app/views/subscriptions/show.html.haml index 2699db9..af1a5a5 100644 --- a/engines/billing/app/views/subscriptions/show.html.haml +++ b/engines/billing/app/views/subscriptions/show.html.haml @@ -3,4 +3,5 @@ Current Subscription = render :partial => "subscription_details", :locals => {:subscription => @subscription} -= link_to t(:cancel_subscription), user_subscription_path(@user, @subscription.id), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn btn-danger' if allow_cancel_subscription(@subscription) +- if allow_cancel_subscription(@subscription) + = btn :cancel_subscription, user_subscription_path(@user, @subscription.id), :confirm => t(:are_you_sure), :method => :delete, :type => 'danger' diff --git a/engines/support/app/views/tickets/_edit_form.html.haml b/engines/support/app/views/tickets/_edit_form.html.haml index 522489e..9adc2cc 100644 --- a/engines/support/app/views/tickets/_edit_form.html.haml +++ b/engines/support/app/views/tickets/_edit_form.html.haml @@ -43,4 +43,4 @@ = f.input :regarding_user, label: Ticket.human_attribute_name(:regarding_user) + regarding_user_link = f.button :loading - if admin? - = link_to t(".destroy", cascade: true), auto_ticket_path(@ticket), :confirm => t("tickets.confirm.destroy.are_you_sure", cascade: true), :method => :delete, :class => 'btn' + = btn t(".destroy", cascade: true), auto_ticket_path(@ticket), confirm: t("tickets.confirm.destroy.are_you_sure", cascade: true), method: :delete diff --git a/engines/support/app/views/tickets/_new_comment_form.html.haml b/engines/support/app/views/tickets/_new_comment_form.html.haml index b829b6b..711421d 100644 --- a/engines/support/app/views/tickets/_new_comment_form.html.haml +++ b/engines/support/app/views/tickets/_new_comment_form.html.haml @@ -10,4 +10,4 @@ = f.button :loading, t(".post_reply"), class: 'btn-primary', value: 'post_reply' - if logged_in? && @ticket.is_open = f.button :loading, t(".reply_and_close"), value: 'reply_and_close' - = link_to t(".cancel"), auto_tickets_path, :class => :btn + = btn t(".cancel"), auto_tickets_path -- cgit v1.2.3 From 8ca32588c969ee9eca986da8cf1de92b39ce3576 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 27 May 2014 17:52:26 +0200 Subject: move users key into layouts scope so it does not conflict with users scope --- app/views/layouts/_header.html.haml | 2 +- config/locales/users.en.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index fbc46b3..e827f60 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -2,7 +2,7 @@ %ul.nav.nav-tabs = # this navigation isn't quite right. also, we will want to active for an identity controller once it is added. %li{:class => ("active" if controller?('users', 'overviews') || params[:user_id])} - = link_to t(:users), users_path + = link_to t(".users"), users_path %li{:class => ("active" if controller?('tickets') && !params[:user_id])} = link_to t(".tickets", cascade: true), tickets_path %li diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index 0375174..f0fcb3d 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -1,5 +1,6 @@ en: - overview: "Overview" + layouts: + users: "Users" user_control_panel: "user control panel" account_settings: "Account Settings" username: "Username" -- cgit v1.2.3 From df1c2438fcfe39edfb46546be8fcee5021f95fc3 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 28 May 2014 09:26:17 +0200 Subject: destroy_btn helper method --- app/helpers/link_helper.rb | 49 ++++++++++++++++++++++ app/views/users/_destroy_account.html.haml | 2 +- .../billing/app/views/subscriptions/show.html.haml | 2 +- .../support/app/views/tickets/_edit_form.html.haml | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 app/helpers/link_helper.rb diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb new file mode 100644 index 0000000..55e392b --- /dev/null +++ b/app/helpers/link_helper.rb @@ -0,0 +1,49 @@ +module LinkHelper + + # + # markup for bootstrap button + # + # takes same arguments as link_to and adds a 'btn' class. + # In addition: + # * the name will be translated if it is a symbol + # * html_options[:type] will be converted into a btn-type class + # + # example: + # btn :home, home_path, type: [:large, :primary] + # + def btn(*args, &block) + html_options = extract_html_options!(args, &block) + type = Array(html_options.delete(:type)) + type.map! {|t| "btn-#{t}"} + html_options[:class] = concat_classes(html_options[:class], 'btn', type) + args[0] = t(args[0]) if args[0].is_a?(Symbol) + link_to *args, html_options, &block + end + + def destroy_btn(*args, &block) + html_options = extract_html_options!(args, &block) + confirmation = t "#{controller_symbol}.confirm.destroy.are_you_sure", + cascade: true + html_options.merge! method: :delete, confirm: confirmation + btn *args, html_options, &block + end + + # + # concat_classes will combine classes in a fairly flexible way. + # it can handle nil, arrays, space separated strings + # it returns a space separated string of classes. + def concat_classes(*classes) + classes.compact! + classes.map {|c| c.respond_to?(:split) ? c.split(' ') : c } + classes.flatten! + classes.join ' ' + end + + def extract_html_options!(args) + if args.count > 2 or args.count > 1 && block_given? + args.extract_options! + else + {} + end + end +end diff --git a/app/views/users/_destroy_account.html.haml b/app/views/users/_destroy_account.html.haml index be003ce..a2c4ddd 100644 --- a/app/views/users/_destroy_account.html.haml +++ b/app/views/users/_destroy_account.html.haml @@ -8,7 +8,7 @@ - else = t(:admin_destroy_account, :username => @user.login) %p= t(:destroy_account_info) -= btn user_path(@user), :method => :delete, :confirm => t(:are_you_sure), :type => "danger" do += destroy_btn user_path(@user), :type => "danger" do %i.icon-remove.icon-white = t(:destroy_my_account) - if @user != current_user and @user.enabled? diff --git a/engines/billing/app/views/subscriptions/show.html.haml b/engines/billing/app/views/subscriptions/show.html.haml index af1a5a5..246ebf0 100644 --- a/engines/billing/app/views/subscriptions/show.html.haml +++ b/engines/billing/app/views/subscriptions/show.html.haml @@ -4,4 +4,4 @@ Subscription = render :partial => "subscription_details", :locals => {:subscription => @subscription} - if allow_cancel_subscription(@subscription) - = btn :cancel_subscription, user_subscription_path(@user, @subscription.id), :confirm => t(:are_you_sure), :method => :delete, :type => 'danger' + = destroy_btn :cancel_subscription, user_subscription_path(@user, @subscription.id), type: 'danger' diff --git a/engines/support/app/views/tickets/_edit_form.html.haml b/engines/support/app/views/tickets/_edit_form.html.haml index 9adc2cc..889dac2 100644 --- a/engines/support/app/views/tickets/_edit_form.html.haml +++ b/engines/support/app/views/tickets/_edit_form.html.haml @@ -43,4 +43,4 @@ = f.input :regarding_user, label: Ticket.human_attribute_name(:regarding_user) + regarding_user_link = f.button :loading - if admin? - = btn t(".destroy", cascade: true), auto_ticket_path(@ticket), confirm: t("tickets.confirm.destroy.are_you_sure", cascade: true), method: :delete + = destroy_btn t(".destroy", cascade: true), auto_ticket_path(@ticket) -- cgit v1.2.3 From ab49a72b52575f3b9fdf13fee47e99dfb82e2a3d Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 29 May 2014 14:57:23 +0200 Subject: html5:
instead of
--- app/controllers/controller_extension/flash.rb | 4 ++-- app/views/pages/terms-of-service.en.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/controller_extension/flash.rb b/app/controllers/controller_extension/flash.rb index 8bc9ee7..1642141 100644 --- a/app/controllers/controller_extension/flash.rb +++ b/app/controllers/controller_extension/flash.rb @@ -37,7 +37,7 @@ module ControllerExtension::Flash def add_flash_errors_for(resource) return if resource.valid? - flash[:error] += "
" - flash[:error] += resource.errors.full_messages.join(".
") + flash[:error] += "
" + flash[:error] += resource.errors.full_messages.join(".
") end end diff --git a/app/views/pages/terms-of-service.en.md b/app/views/pages/terms-of-service.en.md index 7b57027..93490b7 100644 --- a/app/views/pages/terms-of-service.en.md +++ b/app/views/pages/terms-of-service.en.md @@ -3,8 +3,8 @@ This document is our Terms of Service, which describes what activities are allowed, under what conditions we may terminate your account, and asserts our limited liability. It applies to all interactions with **<%=APP_CONFIG[:domain]%>**. Your use of **<%=APP_CONFIG[:domain]%>** services will constitute your agreement to these Terms of Service.

- Summary:
- (1) If you do anything truly evil, we will terminate your account.
+ Summary:
+ (1) If you do anything truly evil, we will terminate your account.
(2) We are not liable for any damages related to the use of this service.

-- cgit v1.2.3 From 6a5e5edf54c76bea3de93475d949c3372d376a81 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 29 May 2014 20:10:11 +0200 Subject: adopt tests to new translations --- engines/support/test/integration/create_ticket_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engines/support/test/integration/create_ticket_test.rb b/engines/support/test/integration/create_ticket_test.rb index 0f8453c..90e9a8a 100644 --- a/engines/support/test/integration/create_ticket_test.rb +++ b/engines/support/test/integration/create_ticket_test.rb @@ -7,7 +7,7 @@ class CreateTicketTest < BrowserIntegrationTest click_on 'Get Help' fill_in 'Subject', with: 'test ticket' fill_in 'Description', with: 'description of the problem goes here' - click_on 'Create Ticket' + click_on 'Submit Ticket' assert page.has_content?("Ticket was successfully created.") assert page.has_content?("You can later access this ticket at the URL") assert page.has_content?(current_url) @@ -20,12 +20,12 @@ 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 'Regarding User', with: 'some user' fill_in 'Description', with: 'description of the problem goes here' - click_on 'Create Ticket' + click_on 'Submit Ticket' assert page.has_content?("is invalid") assert_equal 'invalid data', find_field('Email').value - assert_equal 'some user', find_field('Regarding user').value + assert_equal 'some user', find_field('Regarding User').value end test "prefills fields" do @@ -35,7 +35,7 @@ class CreateTicketTest < BrowserIntegrationTest 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 + assert_equal @user.login, find_field('Regarding User').value end test "no prefill of email without email service" do @@ -44,7 +44,7 @@ class CreateTicketTest < BrowserIntegrationTest click_on "Support Tickets" click_on "New Ticket" assert_equal "", find_field('Email').value - assert_equal @user.login, find_field('Regarding user').value + assert_equal @user.login, find_field('Regarding User').value end test "cleared email field should remain clear" do @@ -55,7 +55,7 @@ class CreateTicketTest < BrowserIntegrationTest fill_in 'Subject', with: 'test ticket' fill_in 'Email', with: '' fill_in 'Description', with: 'description of the problem goes here' - click_on 'Create Ticket' + click_on 'Submit Ticket' ticket = Ticket.last assert_equal "", ticket.email ticket.destroy -- cgit v1.2.3 From 9e3be686ff2751707369894382293924420830d0 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 29 May 2014 20:11:29 +0200 Subject: fix flash for creating anonymous tickets --- engines/support/app/controllers/tickets_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb index 857d071..fab26f3 100644 --- a/engines/support/app/controllers/tickets_controller.rb +++ b/engines/support/app/controllers/tickets_controller.rb @@ -25,7 +25,9 @@ class TicketsController < ApplicationController @ticket.created_by = current_user.id flash_for @ticket if @ticket.save && !logged_in? - flash[:success] = t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) + flash[:success] += t 'tickets.access_ticket_text', + full_url: ticket_url(@ticket.id), + default: "" end respond_with @ticket, :location => auto_ticket_path(@ticket) end -- cgit v1.2.3