Skip to content

Commit

Permalink
Specs and fixes
Browse files Browse the repository at this point in the history
- Add specs and test tools, was 1% now 97% coverage.
- Fixed missing translations and translated mails.
- Add Swedish locale.
- Fixed assets paths and engine issues (mainly for tests to run).
- Updated README.
- Add Travis badge and config.

It was actually very broken, now only the Captcha integration need some
additional attention.
  • Loading branch information
futhr committed Feb 8, 2014
1 parent 89146f2 commit 10943ab
Show file tree
Hide file tree
Showing 36 changed files with 607 additions and 184 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
spec/test_app
Gemfile.lock
.rvmrc
spec/dummy
spec/dummy
tmp
.localeapp
coverage
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: ruby
before_script:
- sh -e /etc/init.d/xvfb start
- export DISPLAY=:99.0
- bundle exec rake test_app
script:
- bundle exec rspec spec
rvm:
- 1.9.3
- 2.0.0
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
source 'https://rubygems.org'
gem 'spree', github: 'spree/spree'

gem 'spree', github: 'spree/spree', branch: 'master'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'

gemspec
10 changes: 10 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
guard "rspec", cmd: "bundle exec rspec", all_on_start: false, all_after_pass: false do
watch("spec/spec_helper.rb") { "spec" }
watch("config/routes.rb") { "spec/controllers" }
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb"}
watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
end
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011 Jorge Calás Lozano, Roman Smirnov, Trung Lê
Copyright (c) 2014 Jorge Calás Lozano, Roman Smirnov, Trung Lê and contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
Spree Email to Friend
=====================

[![Build Status](https://api.travis-ci.org/spree/spree_email_to_friend.png?branch=master)](https://api.travis-ci.org/spree/spree_email_to_friend.png)

The Spree Email to Friend extension enables you to send the product reference to your friend via email.

Installation
------------

Add the following to your <code>Gemfile</code>

gem 'spree_email_to_friend', :git => 'git://github.com/spree/spree_email_to_friend.git'
Add to your `Gemfile`
```ruby
gem 'spree_email_to_friend', github: 'spree/spree_email_to_friend', branch: 'master'
```

Run
```
bundle install
```

Thats all!

Contributing
------------

In the spirit of [free software][1], **everyone** is encouraged to help improve this project.

Here are some ways *you* can contribute:

* by using prerelease versions
* by reporting [bugs][2]
* by suggesting new features
* by writing translations
* by writing or editing documentation
* by writing specifications
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
* by refactoring code
* by resolving [issues][2]
* by reviewing patches

Starting point:

* Fork the repo
* Clone your repo
* Run `bundle install`
* Run `bundle exec rake test_app` to create the test application in `spec/test_app`
* Make your changes
* Ensure specs pass by running `bundle exec rspec spec`
* Submit your pull request

bundle install
Copyright (c) 2014 [Jorge Calás Lozano][5], [Roman Smirnov][6], [Trung Lê][7] and other [contributors][8], released under the [New BSD License][3]


[1]: http://www.fsf.org/licensing/essays/free-sw.html
[2]: https://github.com/spree/spree_email_to_friend/issues
[3]: https://github.com/spree/spree_email_to_friend/blob/master/LICENSE.md
[5]: https://github.com/calas
[6]: https://github.com/romul
[7]: https://github.com/joneslee85
[8]: https://github.com/spree/spree_email_to_friend/graphs/contributors
20 changes: 3 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]

spec = eval(File.read('spree_email_to_friend.gemspec'))

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc "Release to gemcutter"
task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
end

desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree_email_to_friend'
Expand Down
3 changes: 2 additions & 1 deletion Versionfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"2.1.x" => { :branch => 'master' }
"2.2.x" => { :branch => 'master' }
"2.1.x" => { :branch => '2-1-stable' }
"2.0.x" => { :branch => '2-0-stable' }
"1.3.x" => { :branch => '1-3-stable' }
"1.2.x" => { :branch => '1-2-stable' }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require spree/backend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require spree/frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
*= require spree/backend
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
*= require spree/frontend
*/
6 changes: 3 additions & 3 deletions app/controllers/spree/email_sender_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def mail_to_friend
end
end

#extract send message to make easier to override
# Extract send message to make easier to override
def send_message(object, mail_to_friend)
Spree::ToFriendMailer.mail_to_friend(object,@mail_to_friend).deliver
end
Expand All @@ -46,8 +46,8 @@ def find_object
class_name = "Spree::#{(params[:type].titleize)}".constantize
return false if params[:id].blank?

if class_name.respond_to?('find_by_permalink')
@object ||= class_name.find_by_permalink(params[:id])
if class_name.respond_to?('find_by_slug')
@object ||= class_name.find_by_slug(params[:id])
end
if class_name.respond_to?('get_by_param')
@object ||= class_name.get_by_param(params[:id])
Expand Down
8 changes: 4 additions & 4 deletions app/mailers/spree/to_friend_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def mail_to_friend(object, mail)
@mail = mail
opts = {}

if mail.hide_recipients && Spree::Config[:hidden_recipients_to_address]
opts[:to] = Spree::Config[:hidden_recipients_to_address]
opts[:bcc] = mail.recipient_email
if mail.hide_recipients
opts[:to] = mail.recipient_email
opts[:bcc] = mail.recipients
else
opts[:to] = mail.recipient_email
opts[:to] = [mail.recipient_email, mail.recipients.to_s.split(',')].flatten
end
default_url_options[:host] = mail.host
opts[:subject] = mail.subject
Expand Down
11 changes: 5 additions & 6 deletions app/models/spree/mail_to_friend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ class Spree::MailToFriend

EMAILREGEX = /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}\z/i

validates :subject, :presence => true
validates :sender_name, :presence => true
validates :subject, :sender_name, :presence => true
validates :recipient_name, :presence => true, :unless => :is_multi
validates :sender_email, :format => { :with => EMAILREGEX }
validates :recipients, :length => {:minimum => 1, :message => "must contain at least one valid email address"}
validates :invalid_recipients, :length => {:maximum => 0, :message => "must be removed"}
validates :recipients, :length => {:minimum => 1, :message => Spree.t(:recipients, scope: :validation) }
validates :invalid_recipients, :length => {:maximum => 0, :message => Spree.t(:invalid_recipients, scope: :validation) }

def initialize(opts = {})
@sender_email = opts[:sender_email] || ' '
@sender_name = opts[:sender_name] || @sender_email.split('@', 2)[0].titleize
@subject = opts[:subject] || Spree.t('email_to_friend.you_would_like_this', :sender_name => @sender_name, :site => Spree::Config[:site_url])
@subject = opts[:subject] || Spree.t(:sender_subject, scope: :email_to_friend, sender_name: @sender_name, site: Spree::Config[:site_url])

@recipients = []
@invalid_recipients = []
Expand All @@ -41,6 +40,6 @@ def persisted?
end

def is_multi
(@recipients.size + @invalid_recipients.size) > 1
[@recipients, @invalid_recipients].compact.sum.size > 1
end
end
18 changes: 9 additions & 9 deletions app/views/spree/products/_mail_to_friend.text.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<%= mail.recipient_name %>,
<%= @mail.recipient_name %>,

I think you would like this item:
<%= Spree.t(:you_would_like_this_item, scope: :email_to_friend) %>

* <%= object.name %>
* <%= @object.name %>
<% unless mail.message.blank? -%>
<%= mail.message %>
<% unless @mail.message.blank? -%>
<%= @mail.message %>
<% end -%>
<%= mail.sender_name %>
<%= @mail.sender_name %>
Click the link below to view the <%= object.name %> page.
<%= spree.product_url(object) %>
<%= Spree.t(:click_link_to_view, scope: :email_to_friend, name: @object.name) %>
<%= spree.product_url(@object) %>
For more online shopping, visit <%= spree.products_url %>
<%= Spree.t(:visit_page, scope: :email_to_friend, url: spree.products_url) %>
48 changes: 27 additions & 21 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
---
de:
spree:
email_to_friend:
send_to_friend: "Per Email Empfehlen"
tell_about: "Empfehle '%{product}' weiter"
sender_name: "Dein Name"
sender_email: "Deine Emailadresse"
recipient_name: "Name vom Empfänger"
recipient_email: "Email vom Empfänger"
recipient_emails: "Empfänger Emails (mit Beistrich getrennt)"
message: "Nachricht"
send_message: "Diesen Artikel per E-Mail empfehlen!"
mail_sent_to: "Email wurde an %{email} verschickt "
send_to_other: "Jemanden anders empfehlen"
you_would_like_this: "Ich glaube das könnte dir gefallen"

captcha:
captcha_settings: "Captcha Einstellungen"
public_key: "Öffentlichter Schlüssel (Public key)"
private_key: "Privater Schlüssel (Private key)"
manage_keys: "Ihre (re)captcha Schlüssel verwalten"
theme: "Theme"
spree:
email_to_friend:
send_to_friend: "Per Email Empfehlen"
tell_about: "Empfehle '%{product}' weiter"
sender_name: "Dein Name"
sender_email: "Deine Emailadresse"
recipient_name: "Name vom Empfänger"
recipient_email: "Email vom Empfänger"
recipient_emails: "Empfänger Emails (mit Beistrich getrennt)"
message: "Nachricht"
send_message: "Diesen Artikel per E-Mail empfehlen!"
mail_sent_to: "Email wurde an %{email} verschickt "
send_to_other: "Jemanden anders empfehlen"
sender_subject: "Ich glaube das könnte dir gefallen"
you_would_like_this_item: "Ich glaube das könnte dir gefallen:"
click_link_to_view: "Klicken Sie auf den Link unten, um den %{name} Seite zu sehen."
visit_page: "Weitere Online-Shopping, Besuch %{url}"
captcha:
captcha_settings: "Captcha Einstellungen"
public_key: "Öffentlichter Schlüssel (Public key)"
private_key: "Privater Schlüssel (Private key)"
manage_keys: "Ihre (re)captcha Schlüssel verwalten"
use_captcha: "Verwenden Captcha?"
theme: "Thema"
validation:
recipients: "muss mindestens eine gültige E-Mail-Adresse enthalten"
invalid_recipients: "müssen entfernt werden"
10 changes: 8 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
en:
spree:
email_to_friend:
Expand All @@ -12,12 +13,17 @@ en:
send_message: "Tell your friend!"
mail_sent_to: "Mail sent to %{email} "
send_to_other: "Send to other friend"
you_would_like_this: "%{sender_name} wants you to see this item at %{site}"

sender_subject: "%{sender_name} wants you to see this item at %{site}"
you_would_like_this_item: "I think you would like this item:"
click_link_to_view: "Click the link below to view the %{name} page."
visit_page: "For more online shopping, visit %{url}"
captcha:
captcha_settings: "Captcha Settings"
public_key: "Public key"
private_key: "Private key"
manage_keys: "Manage your (re)captcha keys"
use_captcha: "Use Captcha?"
theme: "Theme"
validation:
recipients: "must contain at least one valid email address"
invalid_recipients: "must be removed"
46 changes: 27 additions & 19 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
---
es:
spree:
email_to_friend:
send_to_friend: "Enviar a un amigo"
tell_about: "Enviar {{product}} a un amigo"
sender_name: "Tu nombre"
sender_email: "Tu dirección de correo"
recipient_name: "Nombre de tu amigo"
recipient_email: "Dirección de correo de tu amigo"
message: "Mensaje"
send_message: "¡Enviar a un amigo!"
mail_sent_to: "Mensaje enviado a {{email}} "
send_to_other: "Enviar a otro amigo"
you_would_like_this: "Creo que este artículo te gustará"
captcha:
captcha_settings: "Configuracion de Captcha"
public_key: "Llave pública"
private_key: "Llave privada"
manage_keys: "Administrar tus llaves de recaptcha."
theme: "Tema"
spree:
email_to_friend:
send_to_friend: "Enviar a un amigo"
tell_about: "Enviar %{product} a un amigo"
sender_name: "Tu nombre"
sender_email: "Tu dirección de correo"
recipient_name: "Nombre de tu amigo"
recipient_email: "Dirección de correo de tu amigo"
recipient_emails: "Direcciones de correo electrónico (separadas por comas)"
message: "Mensaje"
send_message: "¡Enviar a un amigo!"
mail_sent_to: "Mensaje enviado a %{email} "
send_to_other: "Enviar a otro amigo"
sender_subject: "Creo que este artículo te gustará"
you_would_like_this_item: "Creo que este artículo te gustará:"
click_link_to_view: "Haga clic en el enlace de abajo para ver la página %{name}."
visit_page: "Para ir de compras más en línea, visite %{url}"
captcha:
captcha_settings: "Configuracion de Captcha"
public_key: "Llave pública"
private_key: "Llave privada"
manage_keys: "Administrar tus llaves de recaptcha."
use_captcha: "Usar Captcha?"
theme: "Tema"
validation:
recipients: "debe contener al menos una dirección de e-mail válida"
invalid_recipients: "debe ser eliminado"
Loading

0 comments on commit 10943ab

Please sign in to comment.