From 7c38622e8f8fd301fbf94995d2e1d9b500e79141 Mon Sep 17 00:00:00 2001 From: Justin Harrison Date: Sat, 26 Mar 2016 13:01:16 -0400 Subject: [PATCH 1/3] Display roles in registration list --- app/views/admin/registrations/index.html.haml | 4 ++++ .../registrations/index.html.haml_spec.rb | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 spec/views/admin/registrations/index.html.haml_spec.rb diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index 4e3a843e..73003021 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -28,6 +28,10 @@ = registration.id %td = registration.name + - @conference.roles.each do |role| + - role.users.each do |user| + - if user == registration.user + %span.label.label-info= role.name.titleize %td = registration.email %td diff --git a/spec/views/admin/registrations/index.html.haml_spec.rb b/spec/views/admin/registrations/index.html.haml_spec.rb new file mode 100644 index 00000000..838ac607 --- /dev/null +++ b/spec/views/admin/registrations/index.html.haml_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'admin/registrations/index' do + let(:conference) { create(:conference, roles: [role1, role2]) } + let(:user) { create(:user) } + let(:role1) { create(:organizer_role, users: [user]) } + let(:role2) { create(:cfp_role, users: [user]) } + + before :each do + assign :conference, conference + assign :registrations, [create(:registration, user: user, conference: conference)] + + render + end + + it 'renders index' do + expect(rendered).to have_selector('table tbody td', text: user.name) + expect(rendered).to have_selector('table tbody td span:nth-of-type(1)', text: role1.name.titleize) + expect(rendered).to have_selector('table tbody td span:nth-of-type(2)', text: role2.name.titleize) + end +end From 18b1ad2b70616230cab1d524559dc60a211f7f19 Mon Sep 17 00:00:00 2001 From: Justin Harrison Date: Tue, 29 Mar 2016 12:04:48 -0400 Subject: [PATCH 2/3] More efficient listing of roles Reduces number of loops from 2 to 1. --- app/views/admin/registrations/index.html.haml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index 73003021..d3ac590b 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -28,10 +28,9 @@ = registration.id %td = registration.name - - @conference.roles.each do |role| - - role.users.each do |user| - - if user == registration.user - %span.label.label-info= role.name.titleize + - registration.user.roles.each do |role| + - if role.resource == @conference + %span.label.label-info= role.name.titleize %td = registration.email %td From 96cf00fda6b0833c518677dd4d76949686e13c97 Mon Sep 17 00:00:00 2001 From: Justin Harrison Date: Tue, 29 Mar 2016 13:14:42 -0400 Subject: [PATCH 3/3] Remove registrations view test View tests don't provide much security, and add too much overhead for what they do secure --- .../registrations/index.html.haml_spec.rb | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 spec/views/admin/registrations/index.html.haml_spec.rb diff --git a/spec/views/admin/registrations/index.html.haml_spec.rb b/spec/views/admin/registrations/index.html.haml_spec.rb deleted file mode 100644 index 838ac607..00000000 --- a/spec/views/admin/registrations/index.html.haml_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe 'admin/registrations/index' do - let(:conference) { create(:conference, roles: [role1, role2]) } - let(:user) { create(:user) } - let(:role1) { create(:organizer_role, users: [user]) } - let(:role2) { create(:cfp_role, users: [user]) } - - before :each do - assign :conference, conference - assign :registrations, [create(:registration, user: user, conference: conference)] - - render - end - - it 'renders index' do - expect(rendered).to have_selector('table tbody td', text: user.name) - expect(rendered).to have_selector('table tbody td span:nth-of-type(1)', text: role1.name.titleize) - expect(rendered).to have_selector('table tbody td span:nth-of-type(2)', text: role2.name.titleize) - end -end