Skip to content

Commit

Permalink
53 3.13 load email drafts (#375)
Browse files Browse the repository at this point in the history
* Featured Issue #55 added initial views

* Featured Issue #55 Added failing tests

* Featured Issue #55 added new routes,controller actions, views and locals

* Featured Issue #55 added emails controller and email model

* Featured Issue #55 Added more tests, improved UI

* Featured Issue #55 fixed failing tests

* Featured Issue #55 fixed merging commit error

* Integrated Email Backend with UI

* Add Copy Button to Email Page

* Add Tests for Email Partial

* Extended acceptance/rejection feature tests

* Failing tests for #55 avoid bcc

* Implement bcc avoiding for #55

* Failing tests for #55 avoid bcc

* Implement avoid bcc with strings for #55

* Make send_email a class method #55

* Integrated updated Email Backend

* Fixed changes that where missing after merge

* Removed DB-Table for Emails

* Renamed TO and BCC in Email UI

* Renamed TO and BCC in Email UI

* Updated test of email sending

* Updated test of email sending

* Updated Email UI, refactored naming scheme and tests

* Removed unused test file

* Fix for not registered Button Click

* Fix broken show/hide recipients option for Email

* Fixed double Negation of hide_recipients

* Simplified Radio Buttons to fix email visibility bug

* Featured Issue #55: Added tests

* Featured Issue #55: Fixed added tests

* Fixed new lines in Emails and truncation of event_details

* Standardize the layout of event_details

* Refactored Email, improved routes, template saving

* Refactored Tests

* Finished refactoring of email service and tests.

* Merge branches '38_3.10_SaveEmailDrafts' and 'dev' of https://github.com/hpi-swt2/workshop-portal into 38_3.10_SaveEmailDrafts

* Fixed Changes to the Gemfile.lock

* Fixed authentication for email page, updated validation to show error messages

* Added Support for default Templates, when no other status is set

* Fixed Test Name

* Fixed broken variable

* Fixed accidently deleted copy recipients button and added a view test

* Fixed naming of css file

* Fixed multiple issues found in code review
- Renamed Templates to Vorlagen in I18n
- Added ability tests

* Fixed paranthesis

* Added invalid testcase

* Removed duplicate tests + moved invalid testcases to own test

* Load Templates via JS

* Fixed email copy + refactored things annoted in PR

* Fixed merged, by adding deleted route and removing old tests

* Fixed controller method in model ;)

* Fixed controller method in model ;)

* That was strange

* Added setting of hide_recipients status saved in template

* Fix whitespace

* Issue #53: Refactored emails.js

* Remove duplicated tests

* Refactored to email_template traits, and featuretest

* Renamed email_template trait names to be consistend with the data

* Added test for setting hide_recipients

* Changed order of not

* Fixed syntax error with not and !
  • Loading branch information
timbasel committed Feb 3, 2017
1 parent b04a745 commit f64012c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
22 changes: 20 additions & 2 deletions app/assets/javascripts/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// All this logic will automatically be available in application.js.

jQuery(function() {
$(document).on('click', "#send-emails-clipboard", function() {
$('#send-emails-clipboard').click(function () {
var recipients = $('#email_recipients')
if(recipients.val.length > 0) {
if(recipients.val().length > 0) {
recipients.select();
try {
document.execCommand('copy');
Expand All @@ -13,4 +13,22 @@ jQuery(function() {
}
}
});

$('.email-template.list-group-item').click(function (e) {
e.preventDefault();
var subject = $(this).children('.template-subject')[0].innerHTML;
var content = $(this).children('.template-content')[0].innerHTML;
var hide_recipients = $(this).children('.template-hide_recipients')[0].innerHTML == "true";

$('#email_subject').val(subject);
$('#email_content').val(content);

var show_recipients_button = $('#email_hide_recipients_false');
var hide_recipients_button = $('#email_hide_recipients_true');

show_recipients_button.attr('checked', !hide_recipients);
show_recipients_button.parent().toggleClass('active', !hide_recipients);
hide_recipients_button.attr('checked', hide_recipients);
hide_recipients_button.parent().toggleClass('active', hide_recipients);
});
});
7 changes: 4 additions & 3 deletions app/views/emails/_templates.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<h3><%= t('.templates') %></h3>
<div class="list-group">
<% @templates.each do |template| %>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading"><%= template[:subject] %></h4>
<p class="list-group-item-text"><%= template[:content] %></p>
<a href="" class="email-template list-group-item">
<p class="template-hide_recipients hidden"><%= template[:hide_recipients] %></p>
<h4 class="template-subject list-group-item-heading"><%= template[:subject] %></h4>
<p class="template-content list-group-item-text"><%= template[:content] %></p>
</a>
<% end %>
</div>
4 changes: 2 additions & 2 deletions spec/controllers/email_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
context "with valid accepted applications" do
before :each do
@application = FactoryGirl.create(:application_letter_accepted, event: @event, user: FactoryGirl.build(:user))
@template = FactoryGirl.create(:email_template_acceptance)
@template = FactoryGirl.create(:email_template, :acceptance)
end

it "sets @email with the email of the accepted application" do
Expand All @@ -34,7 +34,7 @@
context "with valid rejected applications" do
before :each do
@application = FactoryGirl.create(:application_letter_rejected, event: @event, user: FactoryGirl.build(:user))
@template = FactoryGirl.create(:email_template_rejection)
@template = FactoryGirl.create(:email_template, :rejection)
end

it "sets @email with the email of the rejected application" do
Expand Down
18 changes: 9 additions & 9 deletions spec/factories/email_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
hide_recipients false
subject "EmailTemplate-Subject"
content "EmailTemplate-Content"
end

factory :email_template_acceptance, parent: :email_template do
status :acceptance
end
trait :default do
status :default
end

factory :email_template_rejection, parent: :email_template do
status :rejection
end
trait :acceptance do
status :acceptance
end

factory :email_template_default, parent: :email_template do
status :default
trait :rejection do
status :rejection
end
end
end
15 changes: 15 additions & 0 deletions spec/features/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@
expect(page).to have_text(@template_content)
end

scenario "logged in as Organizer I can load an email template", js: true do
login(:organizer)
@template = FactoryGirl.create(:email_template, :acceptance)

visit event_email_show_path(@event, status: :acceptance)
first('.email-template').click


expect(find('#email_hide_recipients_true', visible: false).checked?).to eq(@template.hide_recipients)
expect(find('#email_hide_recipients_false', visible: false).checked?).to eq(!@template.hide_recipients)
expect(page.find('#email_subject').value).to eq(@template.subject)
expect(page.find('#email_content').value).to eq(@template.content)
end


def login(role)
@profile = FactoryGirl.create(:profile)
@profile.user.role = role
Expand Down
10 changes: 5 additions & 5 deletions spec/models/email_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
end

it "accepts valid status values" do
expect(FactoryGirl.build(:email_template_acceptance)).to be_valid
expect(FactoryGirl.build(:email_template_rejection)).to be_valid
expect(FactoryGirl.build(:email_template_default)).to be_valid
expect(FactoryGirl.build(:email_template, :acceptance)).to be_valid
expect(FactoryGirl.build(:email_template, :rejection)).to be_valid
expect(FactoryGirl.build(:email_template, :default)).to be_valid
end

it "rejects invalid status values" do
Expand All @@ -34,8 +34,8 @@
end

it "returns correct templates by status" do
@accepted_template = FactoryGirl.create(:email_template_acceptance)
@rejected_template = FactoryGirl.create(:email_template_rejection)
@accepted_template = FactoryGirl.create(:email_template, :acceptance)
@rejected_template = FactoryGirl.create(:email_template, :rejection)
expect(EmailTemplate.with_status(:acceptance)).to eq([@accepted_template])
expect(EmailTemplate.with_status(:rejection)).to eq([@rejected_template])
end
Expand Down

0 comments on commit f64012c

Please sign in to comment.