diff --git a/app/helpers/mail_helper.rb b/app/helpers/mail_helper.rb new file mode 100644 index 00000000..e5ca70c1 --- /dev/null +++ b/app/helpers/mail_helper.rb @@ -0,0 +1,3 @@ +module MailHelper + +end diff --git a/app/models/table.rb b/app/models/table.rb index ffcfa10f..09c1bbec 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -15,10 +15,22 @@ class Table #validates :list_id, presence: true validates :number, numericality: {greater_than: 0} view :by_supplier_id_and_id, key: [:supplier_id, :_id] + view :by_supplier_id_and_number, key: [:supplier_id, :number] #validates_uniqueness_of :number view :by_number, key: :number + def self.for_supplier(supplier, options = {}) + startkey = options[:from_number].present? ? [supplier.id, options.delete(:from_number).to_i] : [supplier.id] + endkey = options[:to_number].present? ? [supplier.id, options.delete(:to_number).to_i]: [supplier.id, {}] + + total_entries = database.view(by_supplier_id_and_number({startkey: startkey, endkey: endkey, include_docs: false, reduce: true})) + options[:total_entries] = total_entries + with_pagination_options(options) do |options| + database.view(by_supplier_id_and_number({startkey: startkey, endkey: endkey, include_docs: true, reduce: false}.merge(options))) + end + end + def occupied? return @is_occupied if instance_variable_defined?(:'@is_occupied') @is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero? diff --git a/app/views/suppliers/mailer/confirmation_instructions.html.erb b/app/views/suppliers/mailer/confirmation_instructions.html.erb deleted file mode 100644 index a5c4585e..00000000 --- a/app/views/suppliers/mailer/confirmation_instructions.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

Welcome <%= @resource.email %>!

- -

You can confirm your account email through the link below:

- -

<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

diff --git a/app/views/suppliers/mailer/confirmation_instructions.html.slim b/app/views/suppliers/mailer/confirmation_instructions.html.slim new file mode 100644 index 00000000..807dc09e --- /dev/null +++ b/app/views/suppliers/mailer/confirmation_instructions.html.slim @@ -0,0 +1,7 @@ +h3 "Welkom bij Qwaiter #{@resource.email}!" +p + | + Je hebt een account aangevraag bij Qwaiter. Als dit niet de bedoeling is kan je deze email negeren. + Om je account te activeren moet je op de bevestigingslink hieronder klikken: + +p= link_to 'Bevestig mijn Qwaiter account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) diff --git a/app/views/suppliers/tables/index.html.slim b/app/views/suppliers/tables/index.html.slim index adebad23..1478b6f6 100644 --- a/app/views/suppliers/tables/index.html.slim +++ b/app/views/suppliers/tables/index.html.slim @@ -5,10 +5,10 @@ div.page-header= title :index, model_class table.table thead tr - th.link= model_class.human_attribute_name(:number) - th.link= Section.model_name.human - th.timestamp= model_class.human_attribute_name(:created_at) - th.actions=t 'helpers.actions' + th.link data-t="attributes.table.number"= model_class.human_attribute_name(:number) + th.link data-t="models.section"= Section.model_name.human + th.timestamp data-t="attributes.table.created_at"= model_class.human_attribute_name(:created_at) + th.actions data-t="helpers.actions"=t 'helpers.actions' tbody - @tables.each do |table| tr diff --git a/config/application.rb b/config/application.rb index 2586a3bd..ff47a8f3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -75,6 +75,13 @@ module Qwaiter config.assets.precompile += ['supplier/application.css', 'user/application.css', 'qr_sheet/application.css'] config.default_url_options = {format: 'html'} + config.to_prepare do + Devise::Mailer.layout "mail" + Devise::Mailer.class_eval do + helper :mail + end + end + #config.middleware.use Rack::Cors do # allow do # origins '*' diff --git a/config/environments/production.rb b/config/environments/production.rb index d5659407..8c6c07d0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -50,6 +50,9 @@ Qwaiter::Application.configure do # Disable delivery errors, bad email addresses will be ignored config.action_mailer.raise_delivery_errors = false + config.action_mailer.default_url_options = { + host: 'www.qwaiter.com' + } config.action_mailer.smtp_settings = { address: "smtp.gmail.com", port: 587, diff --git a/config/environments/test.rb b/config/environments/test.rb index 30759687..a7504865 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -27,6 +27,9 @@ Qwaiter::Application.configure do # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. + config.action_mailer.default_url_options = { + host: 'www.qwaiter.com' + } config.action_mailer.delivery_method = :test # Raise exception on mass assignment protection for Active Record models diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 90e36697..04eeb97a 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -4,7 +4,7 @@ Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" + config.mailer_sender = 'Qwaiter ' # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" diff --git a/config/locales/devise.nl.yml b/config/locales/devise.nl.yml index 555a1173..931fa64e 100644 --- a/config/locales/devise.nl.yml +++ b/config/locales/devise.nl.yml @@ -36,10 +36,10 @@ nl: forgot_password: Wachtwoord vergeten? send_instructions_button: Stuur mij reset instructies confirmations: - send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' - confirmed: 'Your account was successfully confirmed. You are now signed in.' + send_instructions: 'Er wordt een een e-mail naar je toe gestuurd waarin je je account kan bevestigen.' + confirmed: 'De activatie van je account is successvol. Je bent nu aangemeld!' did_not_receive_instructions_link: "Heeft u geen bevestigingsinstructies ontvangen?" - did_not_receive: Heeft u geen bevestigingsinstructies ontvangen? + did_not_receive: 'Heeft u geen bevestigingsinstructies ontvangen?' registrations: title: Aanmelden button: Aanmelden diff --git a/config/locales/mailer.nl.yml b/config/locales/mailer.nl.yml new file mode 100644 index 00000000..aa269f37 --- /dev/null +++ b/config/locales/mailer.nl.yml @@ -0,0 +1,6 @@ +nl: + mailer: + supplier: + creation: + subject: 'Weklom bij Qwaiter' + title: 'De aanmelding van %{name} bij Qwaiter is gelukt!' diff --git a/spec/mailers/supplier_mailer_spec.rb b/spec/mailers/supplier_mailer_spec.rb new file mode 100644 index 00000000..2181ec5e --- /dev/null +++ b/spec/mailers/supplier_mailer_spec.rb @@ -0,0 +1,5 @@ +require "spec_helper" + +describe SupplierMailer do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/table_spec.rb b/spec/models/table_spec.rb new file mode 100644 index 00000000..4831f981 --- /dev/null +++ b/spec/models/table_spec.rb @@ -0,0 +1,34 @@ +# encoding: UTF-8 + +require 'spec_helper' + +describe Table do + describe 'for_supplier' do + let(:supplier){ create(:supplier) } + let(:options){ Hash.new } + subject{ Table.for_supplier(supplier, options) } + it "should return an empty array by default" do + subject.should be_empty + end + describe 'with multiple tables' do + before do + @table1 = create :table, supplier: supplier, number: 2 + @table2 = create :table, supplier: supplier, number: 4 + @table3 = create :table, supplier: supplier, number: 6 + @table4 = create :table, number: 4 + + end + it "returns all by default" do + subject.should == [@table1, @table2, @table3] + end + + it "should paginate the result" do + options[:per_page] = 2 + subject.size.should == 2 + subject.total_count.should == 3 + + end + end + end + +end