Skip to content

Commit

Permalink
Merge branch 'develop' into feature/rubocop
Browse files Browse the repository at this point in the history
Conflicts:
	app/mailers/cart_mailer.rb
	test/controllers/registrations_controller_test.rb
  • Loading branch information
KonstantinKo committed Apr 8, 2015
2 parents c7973a5 + 23e2873 commit 172223c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 46 deletions.
47 changes: 26 additions & 21 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def new
# Check if parameters have been provided by a landing page and set object attributes accordingly
resource.assign_attributes(params[:external_user].for(resource).on(:create).refine) if params[:external_user]

@validatable = devise_mapping.validatable?
if @validatable
if devise_mapping.validatable?
@minimum_password_length = resource_class.password_length.min
end
respond_with self.resource
Expand All @@ -45,29 +44,15 @@ def edit
end

def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)

self.resource = resource_class.to_adapter.get!(send(:"current_#{ resource_name }").to_key)
address_params = params[:address] ? params.for(Address).refine : {}
resource.build_standard_address_from address_params
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)

successfully_updated = update_account(account_update_params)
if successfully_updated

resource.save_already_validated_standard_address!

if is_navigational_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:changed_email : :updated
set_flash_message :notice, flash_key
end

sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
if update_account(account_update_params)
actions_for_successful_update_for resource, prev_unconfirmed_email
else
clean_up_passwords resource
resource.image.save if resource.image
respond_with resource
actions_for_unsuccessful_update_for resource
end
end

Expand Down Expand Up @@ -104,6 +89,26 @@ def update_account(account_update_params)
end
end

def actions_for_successful_update_for resource, prev_unconfirmed_email = nil
resource.save_already_validated_standard_address!

if is_navigational_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:changed_email : :updated
set_flash_message :notice, flash_key
end

sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
end

def actions_for_unsuccessful_update_for resource
clean_up_passwords resource
resource.image.save if resource.image
respond_with resource
end


protected

def configure_permitted_parameters
Expand Down
45 changes: 25 additions & 20 deletions app/mailers/cart_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ class CartMailer < ActionMailer::Base
def buyer_email(cart)
cart.line_item_groups.each do |lig|
add_image_attachments_for lig

if lig.seller.is_a?(LegalEntity) && lig.seller.terms && lig.seller.cancellation
filename = "#{ lig.seller_nickname }_agb_und_widerrruf.pdf"
attachments[filename] = TermsAndCancellationPdf.new(lig).render
end

unless lig.business_transactions.select { |bt| bt.selected_transport == 'bike_courier' }.empty?
filename = $courier['tos']
attachments[filename] = File.read(Rails.root.join("app/assets/docs/#{ filename }"))
end
add_legal_documents_for lig
add_bike_courier_documents_for lig
end

@cart = cart
Expand All @@ -39,15 +31,15 @@ def seller_email(line_item_group)
end

def courier_notification(business_transaction)
@business_transaction = business_transaction
@buyer = business_transaction.buyer
@seller = business_transaction.seller
@subject = '[Fairmondo] Artikel ausliefern'
@courier_email = Rails.env == 'production' ? $courier['email'] : 'test@test.com'

if @business_transaction.line_item_group.paypal_payment && @business_transaction.line_item_group.paypal_payment.confirmed? # && @business_transaction.ready?
mail(to: @courier_email, subject: @subject, bcc: 'bybike@fairmondo.de')
end
@business_transaction = business_transaction
@buyer = business_transaction.buyer
@seller = business_transaction.seller
@subject = "[Fairmondo] Artikel ausliefern"
@courier_email = Rails.env == 'production' ? $courier['email'] : 'test@test.com'

if @business_transaction.line_item_group.paypal_payment && @business_transaction.line_item_group.paypal_payment.confirmed?
mail(to: @courier_email, subject: @subject, bcc: 'bybike@fairmondo.de')
end
end

def voucher_paid_email payment_id
Expand Down Expand Up @@ -75,14 +67,27 @@ def send_cart(cart_id, email)
end

private

def add_image_attachments_for line_item_group
line_item_group.line_items.each do |li|
attachment = image_attachment_for li
attachments.inline[li.article.title_image.image_file_name] = attachment if attachment
end
end

def add_legal_documents_for lig
if lig.seller.is_a?(LegalEntity) && lig.seller.terms && lig.seller.cancellation
filename = "#{ lig.seller_nickname }_agb_und_widerrruf.pdf"
attachments[filename] = TermsAndCancellationPdf.new(lig).render
end
end

def add_bike_courier_documents_for lig
unless lig.business_transactions.select{|bt| bt.selected_transport == 'bike_courier'}.empty?
filename = $courier['tos']
attachments[filename] = File.read(Rails.root.join("app/assets/docs/#{ filename }"))
end
end

def image_attachment_for line_item
image = line_item.article.title_image
if image
Expand Down
2 changes: 1 addition & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ de:
notices:
applied: "Die Vorlage %{name} wurde erfolgreich übernommen"
prompts:
article_id: "Bitte wähle eine Vorlage"
article_id: "Leere Vorlage"
errors:
article_id: "Bitte wähle eine Vorlage"

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/registrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
user = FactoryGirl.create(:user)
sign_in user
Image.any_instance.expects(:save)
put :update, user: { nickname: user.nickname, image_attributes: FactoryGirl.attributes_for(:user_image) }, address: { first_name: '' } # invalid params
put :update, { user: { nickname: user.nickname, image_attributes: FactoryGirl.attributes_for(:user_image) }, address: { first_name: "" } }# invalid params
end
end
end
6 changes: 3 additions & 3 deletions test/mailers/cart_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

it 'must contain courier terms when at least one transaction has
selected_transport bike_courier' do
bt = FactoryGirl.create :business_transaction,
line_item_group_id: cart.line_item_groups.first.id
FactoryGirl.create :business_transaction,
line_item_group_id: cart.line_item_groups.first.id
BusinessTransaction.any_instance.stubs(:selected_transport)
.returns('bike_courier')
mail = CartMailer.buyer_email(cart)
Expand Down Expand Up @@ -56,7 +56,7 @@

it 'sends email to courier service' do
business_transaction = FactoryGirl.create(:business_transaction, :transport_bike_courier, :paypal, :sold, state: 'ready')
payment = FactoryGirl.create :payment, line_item_group: business_transaction.line_item_group, state: 'confirmed'
FactoryGirl.create :payment, line_item_group: business_transaction.line_item_group, state: 'confirmed'
seller = business_transaction.seller
buyer = business_transaction.buyer
mail = CartMailer.courier_notification(business_transaction)
Expand Down

0 comments on commit 172223c

Please sign in to comment.