diff --git a/Gemfile b/Gemfile
index 97e96e0..b04c635 100644
--- a/Gemfile
+++ b/Gemfile
@@ -30,6 +30,8 @@ end
group :test do
gem 'ruby-debug19', :require => 'ruby-debug'
gem 'rspec-rails'
+ gem 'factory_girl_rails'
+ gem 'capybara'
end
group :development do
gem 'ruby-debug19', :require => 'ruby-debug'
diff --git a/Gemfile.lock b/Gemfile.lock
index 093c7d2..d910717 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,15 +1,15 @@
GIT
remote: git://github.com/bterkuile/couch_potato.git
- revision: 11a7c6edf216a2460e2f8775d52e799662b3d9d1
+ revision: 2f0252bc1b93675ccc4f0ff6a193c2acff59bc2e
specs:
- couch_potato (0.5.7)
+ couch_potato (0.6.0)
activemodel
couchrest (>= 1.0.1)
- json
+ json (~> 1.6.0)
GIT
remote: git://github.com/bterkuile/simply_stored.git
- revision: a49f8044be2ad4d587e73d53bff9ffbe4aa6d7e3
+ revision: abe990e1d97763ef90d3ff010d449bf2adf5a227
specs:
simply_stored (0.5.4)
activesupport
@@ -35,31 +35,31 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.2.2)
- actionpack (= 3.2.2)
- mail (~> 2.4.0)
- actionpack (3.2.2)
- activemodel (= 3.2.2)
- activesupport (= 3.2.2)
+ actionmailer (3.2.3)
+ actionpack (= 3.2.3)
+ mail (~> 2.4.4)
+ actionpack (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
- rack-cache (~> 1.1)
+ rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
- activemodel (3.2.2)
- activesupport (= 3.2.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
- activerecord (3.2.2)
- activemodel (= 3.2.2)
- activesupport (= 3.2.2)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.2.2)
- activemodel (= 3.2.2)
- activesupport (= 3.2.2)
- activesupport (3.2.2)
+ activeresource (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
archive-tar-minitar (0.5.2)
@@ -68,6 +68,15 @@ GEM
bourbon (1.4.0)
sass (>= 3.1)
builder (3.0.0)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
cocaine (0.2.1)
coffee-script (2.2.0)
coffee-script-source
@@ -91,6 +100,12 @@ GEM
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ factory_girl (3.0.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (3.0.0)
+ factory_girl (~> 3.0.0)
+ railties (>= 3.0.0)
+ ffi (1.0.11)
haml (3.1.4)
haml-rails (0.3.4)
actionpack (~> 3.0)
@@ -103,7 +118,7 @@ GEM
jquery-rails (2.0.1)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
- json (1.6.5)
+ json (1.6.6)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
mail (2.4.4)
@@ -112,10 +127,12 @@ GEM
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.0.4)
- orm_adapter (0.0.6)
- paperclip (2.7.0)
- activerecord (>= 2.3.0)
- activesupport (>= 2.3.2)
+ nokogiri (1.5.2)
+ orm_adapter (0.0.7)
+ paperclip (3.0.1)
+ activemodel (>= 3.0.0)
+ activerecord (>= 3.0.0)
+ activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
polyglot (0.3.3)
@@ -126,17 +143,17 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.2)
- actionmailer (= 3.2.2)
- actionpack (= 3.2.2)
- activerecord (= 3.2.2)
- activeresource (= 3.2.2)
- activesupport (= 3.2.2)
+ rails (3.2.3)
+ actionmailer (= 3.2.3)
+ actionpack (= 3.2.3)
+ activerecord (= 3.2.3)
+ activeresource (= 3.2.3)
+ activesupport (= 3.2.3)
bundler (~> 1.0)
- railties (= 3.2.2)
- railties (3.2.2)
- actionpack (= 3.2.2)
- activesupport (= 3.2.2)
+ railties (= 3.2.3)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
@@ -169,11 +186,17 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
+ rubyzip (0.9.6.1)
sass (3.1.15)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -188,18 +211,22 @@ GEM
tzinfo (0.3.32)
warden (1.1.1)
rack (>= 1.0)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bourbon
+ capybara
cmtool!
coffee-script
couch_potato!
devise
devise_simply_stored
email_validator
+ factory_girl_rails
haml-rails
jquery-rails
paperclip
diff --git a/app/assets/images/cmtool/logo.png b/app/assets/images/cmtool/logo.png
new file mode 100644
index 0000000..5153593
Binary files /dev/null and b/app/assets/images/cmtool/logo.png differ
diff --git a/app/assets/images/cmtool/logo.svg b/app/assets/images/cmtool/logo.svg
new file mode 100644
index 0000000..a9411e1
--- /dev/null
+++ b/app/assets/images/cmtool/logo.svg
@@ -0,0 +1,186 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/assets/stylesheets/cmtool/sessions/structure.css.sass b/app/assets/stylesheets/cmtool/sessions/structure.css.sass
index 7238017..01cb983 100644
--- a/app/assets/stylesheets/cmtool/sessions/structure.css.sass
+++ b/app/assets/stylesheets/cmtool/sessions/structure.css.sass
@@ -60,7 +60,7 @@ body, html
#content
h2
margin: 10px 0
- background-image: image-url("sessions/logo.png")
+ background-image: image-url("cmtool/logo.png")
background-repeat: no-repeat
background-position: right bottom
padding: 18px
diff --git a/app/controllers/cmtool/application_controller.rb b/app/controllers/cmtool/application_controller.rb
index 4917ad9..85c0b84 100644
--- a/app/controllers/cmtool/application_controller.rb
+++ b/app/controllers/cmtool/application_controller.rb
@@ -1,6 +1,6 @@
module Cmtool
class ApplicationController < ::ApplicationController
- before_filter :authenticate_user!, :set_locale
+ before_filter :authenticate_user!, :authorize_user, :check_environment, :set_locale
private
@@ -11,5 +11,15 @@ module Cmtool
I18n.locale = :en
end
end
+
+ def authorize_user
+
+ end
+
+ def check_environment
+ @cmtool_warnings ||= []
+ @cmtool_warnings << 'no_host_specified' unless ( Rails.application.config.action_mailer.default_url_options[:host] rescue false) ||
+ Rails.application.default_url_options[:host].present?
+ end
end
end
diff --git a/app/controllers/cmtool/contact_forms_controller.rb b/app/controllers/cmtool/contact_forms_controller.rb
index 048f243..cde7741 100644
--- a/app/controllers/cmtool/contact_forms_controller.rb
+++ b/app/controllers/cmtool/contact_forms_controller.rb
@@ -1,5 +1,7 @@
module Cmtool
class Cmtool::ContactFormsController < Cmtool::ApplicationController
+ skip_before_filter :authenticate_user!, :authorize_user, only: :add
+
# GET /contact_forms
# GET /contact_forms.xml
def index
@@ -81,5 +83,14 @@ module Cmtool
format.xml { head :ok }
end
end
+
+ def add
+ @contact_form = Cmtool::ContactForm.new(params[:contact_form])
+ if @contact_form.save
+ redirect_to :back, notice: I18n.t('cmtool.contact_form.submitted')
+ else
+ redirect_to :back, alert: I18n.t('cmtool.contact_form.submission_failed', reason: @contact_form.errors.full_messages.join(', '))
+ end
+ end
end
end
diff --git a/app/controllers/cmtool/newsletter_subscriptions_controller.rb b/app/controllers/cmtool/newsletter_subscriptions_controller.rb
index 4a11e20..fb1f3cc 100644
--- a/app/controllers/cmtool/newsletter_subscriptions_controller.rb
+++ b/app/controllers/cmtool/newsletter_subscriptions_controller.rb
@@ -1,5 +1,7 @@
module Cmtool
class Cmtool::NewsletterSubscriptionsController < Cmtool::ApplicationController
+ skip_before_filter :authenticate_user!, :authorize_user, only: :add
+
# GET /newsletter_subscriptions
# GET /newsletter_subscriptions.xml
def index
@@ -81,5 +83,14 @@ module Cmtool
format.xml { head :ok }
end
end
+
+ def add
+ @newsletter_subscription = Cmtool::NewsletterSubscription.new(params[:newsletter_subscription])
+ if @newsletter_subscription.save
+ redirect_to :back, notice: I18n.t('cmtool.newsletter_subscription.subscribed')
+ else
+ redirect_to :back, alert: I18n.t('cmtool.newsletter_subscription.subscription_failed', reason: @newsletter_subscription.errors.full_messages.join(', '))
+ end
+ end
end
end
diff --git a/app/controllers/cmtool/passwords_controller.rb b/app/controllers/cmtool/passwords_controller.rb
index ee474cc..17da516 100644
--- a/app/controllers/cmtool/passwords_controller.rb
+++ b/app/controllers/cmtool/passwords_controller.rb
@@ -1,5 +1,5 @@
module Cmtool
class PasswordsController < Devise::PasswordsController
- layout 'cmtool/application'
+ layout 'cmtool/sessions'
end
end
diff --git a/app/helpers/cmtool/application_helper.rb b/app/helpers/cmtool/application_helper.rb
index 26ac07b..8d36441 100644
--- a/app/helpers/cmtool/application_helper.rb
+++ b/app/helpers/cmtool/application_helper.rb
@@ -28,6 +28,10 @@ module Cmtool
end
alias are_you_sure? are_you_sure
+ def warnings
+ @cmtool_warnings
+ end
+
def boolean_text(yes)
yes.present? ? t('cmtool.general.yes') : t('cmtool.general.no')
end
diff --git a/app/models/cmtool/image.rb b/app/models/cmtool/image.rb
index 1940468..6a9f492 100644
--- a/app/models/cmtool/image.rb
+++ b/app/models/cmtool/image.rb
@@ -5,9 +5,11 @@ module Cmtool
property :file_file_name
property :file_content_type
- property :file_file_size, :type => Fixnum
- property :file_updated_at, :type => Time
- has_attached_file :file, :styles => { :page => '675x10000>', :medium => "354x1000>", :thumb => "150x1250>" }
+ property :file_file_size, type: Fixnum
+ property :file_updated_at, type: Time
+ has_attached_file :file, styles: { page: '675x10000>', medium: "354x1000>", thumb: "150x1250>" },
+ path: ":rails_root/public/system/:attachment/:id/:style.:extension",
+ url: "/system/:attachment/:id/:style.:extension"
belongs_to :directory
diff --git a/app/views/cmtool/application/_alerts.html.haml b/app/views/cmtool/application/_alerts.html.haml
index 93cae72..c4c8abf 100644
--- a/app/views/cmtool/application/_alerts.html.haml
+++ b/app/views/cmtool/application/_alerts.html.haml
@@ -8,3 +8,13 @@
.icon
.text
=raw flash[:notice]
+- if warnings.any?
+ .message.warning.ui-state-highlight
+ .icon
+ .text
+ %ul
+ - for warning in warnings
+ - if warning.is_a?(Hash)
+ %li.warning= t("cmtool.warnings.#{warning.delete(:message)}", warning)
+ - else
+ %li.warning= t("cmtool.warnings.#{warning}")
diff --git a/app/views/layouts/cmtool/application.html.haml b/app/views/layouts/cmtool/application.html.haml
index a667337..af75349 100644
--- a/app/views/layouts/cmtool/application.html.haml
+++ b/app/views/layouts/cmtool/application.html.haml
@@ -26,7 +26,7 @@
%li{:class => controller_name == 'faqs' ? 'ui-state-active' : 'ui-state-default'}=link_to Cmtool::Faq.model_name.human_plural, cmtool.faqs_path
%li{:class => controller_name == 'quotes' ? 'ui-state-active' : 'ui-state-default'}=link_to Cmtool::Quote.model_name.human_plural, cmtool.quotes_path
%li{:class => %w[contact_forms demo_requests call_requests newsletter_subscriptions].include?(controller_name) ? ['ui-state-active', 'parent'] : ['ui-state-default', 'parent']}
- %span.title Formulieren
+ %span.title= t('cmtool.menu.forms.title')
%ul.child-menu
%li{:class => controller_name == 'contact_forms' ? 'ui-state-active' : 'ui-state-default'}=link_to Cmtool::ContactForm.model_name.human_plural, cmtool.contact_forms_path
%li{:class => controller_name == 'newsletter_subscriptions' ? 'ui-state-active' : 'ui-state-default'}=link_to Cmtool::NewsletterSubscription.model_name.human_plural, cmtool.newsletter_subscriptions_path
diff --git a/config/locales/cmtool.en.yml b/config/locales/cmtool.en.yml
index 3bb4e67..abfe719 100644
--- a/config/locales/cmtool.en.yml
+++ b/config/locales/cmtool.en.yml
@@ -6,6 +6,9 @@ en:
are_you_sure: 'Are you sure?'
are_you_sure_with_name: 'Are you sure you want to delete %{model} %{name}?'
empty_result: No %{models} found
+ menu:
+ forms:
+ title: Form
action:
index:
title: List %{models}
@@ -30,6 +33,12 @@ en:
label: Add %{image}
news:
remove_image: Remove image
+ newsletter_subscription:
+ subscribed: You subscribed successfully to the newsletter
+ subscription_failed: 'There was a problem with your subscription %{reason}'
+ contact_form:
+ submitted: You successfully submitted the contact form
+ submission_failed: 'There was a problem with the contact form submission %{reason}'
quote:
remove_image: Remove image
sessions:
@@ -39,6 +48,8 @@ en:
errors:
form:
title: 'The action could not be completed because of %{count} reasons'
+ warnings:
+ no_host_specified: 'You did not specify a host in config/environments/:env (config.action_mailer.default_url_options = { :host => "example.com" })'
activemodel:
models:
page: Page
diff --git a/config/routes.rb b/config/routes.rb
index e35e758..529821d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -26,8 +26,12 @@ Cmtool::Engine.routes.draw do
end
# ADMIN FORMS
- resources :contact_forms
- resources :newsletter_subscriptions
+ resources :contact_forms do
+ post :add
+ end
+ resources :newsletter_subscriptions do
+ post :add
+ end
# USER MANAGEMENT
resources :users
diff --git a/lib/cmtool/includes/user.rb b/lib/cmtool/includes/user.rb
index c0c60ac..8c5451a 100644
--- a/lib/cmtool/includes/user.rb
+++ b/lib/cmtool/includes/user.rb
@@ -2,12 +2,11 @@ module Cmtool
module Includes
module User
def self.included(klass)
- klass.extend Devise::Models
klass.send :include, SimplyStored::Couch
klass.send :include, Devise::Orm::SimplyStored
klass.send :include, InstanceMethods
+ klass.send :extend, ClassMethods
- klass.property :employee_email
klass.property :is_admin, type: :boolean
klass.property :active, type: :boolean, default: true
@@ -36,12 +35,17 @@ module Cmtool
end
def generate_password!
- @password_haystack ||= (:a..:z).to_a + (:A..:Z).to_a + (0..9).to_a
- @generated_password = @password_haystack.sample(8).join
+ @generated_password = self.class.password_haystack.sample(8).join
self.password = @generated_password
self.password_confirmation = @generated_password
end
end
+
+ module ClassMethods
+ def password_haystack
+ @password_haystack ||= (:a..:z).to_a + (:A..:Z).to_a + (0..9).to_a
+ end
+ end
end
end
end
diff --git a/spec/controllers/faqs_controller_spec.rb b/spec/controllers/faqs_controller_spec.rb
new file mode 100644
index 0000000..48510d9
--- /dev/null
+++ b/spec/controllers/faqs_controller_spec.rb
@@ -0,0 +1,154 @@
+require 'spec_helper'
+
+describe Cmtool::FaqsController do
+ before :each do
+ sign_in @user
+ end
+
+ describe 'no user is signed in' do
+ before :each do
+ sign_out @user
+ end
+ it "should not allow acces when no user is logged in" do
+ faq = create :faq
+ get :index
+ response.should be_redirect
+ end
+ end
+
+ describe "GET index" do
+ it "assigns all faqs as @faqs" do
+ faq = create :faq
+ get :index
+ assigns(:faqs).should eq([faq])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested faq as @faq" do
+ faq = create :faq
+ get :show, :id => faq.id
+ assigns(:faq).should eq(faq)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new faq as @faq" do
+ get :new
+ assigns(:faq).should be_a_new(Cmtool::Faq)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested faq as @faq" do
+ faq = create :faq
+ get :edit, :id => faq.id
+ assigns(:faq).should eq(faq)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Cmtool::Faq" do
+ expect {
+ post :create, :faq => build(:faq).attributes
+ }.to change(Cmtool::Faq, :count).by(1)
+ end
+
+ it "assigns a newly created faq as @faq" do
+ post :create, :faq => build(:faq).attributes
+ assigns(:faq).should be_a(Cmtool::Faq)
+ assigns(:faq).should be_persisted
+ end
+
+ it "redirects to the faqs faq" do
+ post :create, :faq => build(:faq).attributes
+ response.should redirect_to(Cmtool::Faq.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved faq as @faq" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::Faq.any_instance.stub(:save).and_return(false)
+ post :create, :faq => {}
+ assigns(:faq).should be_a_new(Cmtool::Faq)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::Faq.any_instance.stub(:save).and_return(false)
+ post :create, :faq => {}
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested faq" do
+ faq = create(:faq)
+ # Assuming there are no other faqs in the database, this
+ # specifies that the Cmtool::Faq created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Cmtool::Faq.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => faq.id, :faq => {'these' => 'params'}
+ end
+
+ it "assigns the requested faq as @faq" do
+ faq = create(:faq)
+ put :update, :id => faq.id, :faq => faq.attributes
+ assigns(:faq).should eq(faq)
+ end
+
+ it "redirects to the faq" do
+ faq = create(:faq)
+ put :update, :id => faq.id, :faq => faq.attributes
+ response.should redirect_to(faq)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the faq as @faq" do
+ faq = create(:faq)
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::Faq.any_instance.stub(:save).and_return(false)
+ put :update, :id => faq.id, :faq => {}
+ assigns(:faq).should eq(faq)
+ end
+
+ it "re-renders the 'edit' template" do
+ faq = create(:faq)
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::Faq.any_instance.stub(:save).and_return(false)
+ put :update, :id => faq.id, :faq => {}
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested faq" do
+ @request.env['HTTP_REFERER'] = faqs_path
+ faq = create(:faq)
+ expect {
+ delete :destroy, :id => faq.id
+ }.to change(Cmtool::Faq, :count).by(-1)
+ end
+
+ it "redirects to the faqs list" do
+ @request.env['HTTP_REFERER'] = faqs_path
+ faq = create(:faq)
+ delete :destroy, :id => faq.id
+ response.should redirect_to(faqs_path)
+ end
+ it "redirects to the faqs list when called from edit page" do
+ faq = create(:faq)
+ @request.env['HTTP_REFERER'] = edit_faq_path(faq)
+ delete :destroy, :id => faq.id
+ response.should redirect_to(faqs_path)
+ end
+ end
+
+end
diff --git a/spec/controllers/newsletter_subscriptions_controller_spec.rb b/spec/controllers/newsletter_subscriptions_controller_spec.rb
new file mode 100644
index 0000000..eaa372c
--- /dev/null
+++ b/spec/controllers/newsletter_subscriptions_controller_spec.rb
@@ -0,0 +1,161 @@
+require 'spec_helper'
+
+describe Cmtool::NewsletterSubscriptionsController do
+ before :each do
+ sign_in @user
+ end
+
+ describe 'no user is signed in' do
+ before :each do
+ sign_out @user
+ end
+ it "should not allow acces when no user is logged in" do
+ newsletter_subscription = create :newsletter_subscription
+ get :index
+ response.should be_redirect
+ end
+
+ it "should add a subscription without authentication" do
+ @request.env['HTTP_REFERER'] = '/'
+ expect {
+ post :add, newsletter_subscription: {email: "unauthenticated@example.com"}
+ }.to change(Cmtool::NewsletterSubscription, :count).by(1)
+ end
+ end
+
+ describe "GET index" do
+ it "assigns all newsletter_subscriptions as @newsletter_subscriptions" do
+ newsletter_subscription = create :newsletter_subscription
+ get :index
+ assigns(:newsletter_subscriptions).should eq([newsletter_subscription])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested newsletter_subscription as @newsletter_subscription" do
+ newsletter_subscription = create :newsletter_subscription
+ get :show, :id => newsletter_subscription.id
+ assigns(:newsletter_subscription).should eq(newsletter_subscription)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new newsletter_subscription as @newsletter_subscription" do
+ get :new
+ assigns(:newsletter_subscription).should be_a_new(Cmtool::NewsletterSubscription)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested newsletter_subscription as @newsletter_subscription" do
+ newsletter_subscription = create :newsletter_subscription
+ get :edit, :id => newsletter_subscription.id
+ assigns(:newsletter_subscription).should eq(newsletter_subscription)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Cmtool::NewsletterSubscription" do
+ expect {
+ post :create, :newsletter_subscription => build(:newsletter_subscription).attributes
+ }.to change(Cmtool::NewsletterSubscription, :count).by(1)
+ end
+
+ it "assigns a newly created newsletter_subscription as @newsletter_subscription" do
+ post :create, :newsletter_subscription => build(:newsletter_subscription).attributes
+ assigns(:newsletter_subscription).should be_a(Cmtool::NewsletterSubscription)
+ assigns(:newsletter_subscription).should be_persisted
+ end
+
+ it "redirects to the newsletter_subscriptions newsletter_subscription" do
+ post :create, :newsletter_subscription => build(:newsletter_subscription).attributes
+ response.should redirect_to(Cmtool::NewsletterSubscription.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved newsletter_subscription as @newsletter_subscription" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::NewsletterSubscription.any_instance.stub(:save).and_return(false)
+ post :create, :newsletter_subscription => {}
+ assigns(:newsletter_subscription).should be_a_new(Cmtool::NewsletterSubscription)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::NewsletterSubscription.any_instance.stub(:save).and_return(false)
+ post :create, :newsletter_subscription => {}
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested newsletter_subscription" do
+ newsletter_subscription = create(:newsletter_subscription)
+ # Assuming there are no other newsletter_subscriptions in the database, this
+ # specifies that the Cmtool::NewsletterSubscription created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Cmtool::NewsletterSubscription.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => newsletter_subscription.id, :newsletter_subscription => {'these' => 'params'}
+ end
+
+ it "assigns the requested newsletter_subscription as @newsletter_subscription" do
+ newsletter_subscription = create(:newsletter_subscription)
+ put :update, :id => newsletter_subscription.id, :newsletter_subscription => newsletter_subscription.attributes
+ assigns(:newsletter_subscription).should eq(newsletter_subscription)
+ end
+
+ it "redirects to the newsletter_subscription" do
+ newsletter_subscription = create(:newsletter_subscription)
+ put :update, :id => newsletter_subscription.id, :newsletter_subscription => newsletter_subscription.attributes
+ response.should redirect_to(newsletter_subscription)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the newsletter_subscription as @newsletter_subscription" do
+ newsletter_subscription = create(:newsletter_subscription)
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::NewsletterSubscription.any_instance.stub(:save).and_return(false)
+ put :update, :id => newsletter_subscription.id, :newsletter_subscription => {}
+ assigns(:newsletter_subscription).should eq(newsletter_subscription)
+ end
+
+ it "re-renders the 'edit' template" do
+ newsletter_subscription = create(:newsletter_subscription)
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cmtool::NewsletterSubscription.any_instance.stub(:save).and_return(false)
+ put :update, :id => newsletter_subscription.id, :newsletter_subscription => {}
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested newsletter_subscription" do
+ @request.env['HTTP_REFERER'] = newsletter_subscriptions_path
+ newsletter_subscription = create(:newsletter_subscription)
+ expect {
+ delete :destroy, :id => newsletter_subscription.id
+ }.to change(Cmtool::NewsletterSubscription, :count).by(-1)
+ end
+
+ it "redirects to the newsletter_subscriptions list" do
+ @request.env['HTTP_REFERER'] = newsletter_subscriptions_path
+ newsletter_subscription = create(:newsletter_subscription)
+ delete :destroy, :id => newsletter_subscription.id
+ response.should redirect_to(newsletter_subscriptions_path)
+ end
+ it "redirects to the newsletter_subscriptions list when called from edit page" do
+ newsletter_subscription = create(:newsletter_subscription)
+ @request.env['HTTP_REFERER'] = edit_newsletter_subscription_path(newsletter_subscription)
+ delete :destroy, :id => newsletter_subscription.id
+ response.should redirect_to(newsletter_subscriptions_path)
+ end
+ end
+
+end
diff --git a/app/models/user.rb b/spec/dummy/app/models/user.rb
similarity index 100%
rename from app/models/user.rb
rename to spec/dummy/app/models/user.rb
diff --git a/spec/dummy/config/environments/.development.rb.swp b/spec/dummy/config/environments/.development.rb.swp
new file mode 100644
index 0000000..e5ee5b3
Binary files /dev/null and b/spec/dummy/config/environments/.development.rb.swp differ
diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb
index 50105b3..183e87d 100644
--- a/spec/dummy/config/environments/development.rb
+++ b/spec/dummy/config/environments/development.rb
@@ -22,6 +22,8 @@ Dummy::Application.configure do
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
+ config.action_mailer.default_url_options = { :host => "http://localhost:3000" }
+
# Raise exception on mass assignment protection for Active Record models
# config.active_record.mass_assignment_sanitizer = :strict
diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb
index f1a4814..6feb3d2 100644
--- a/spec/dummy/config/environments/test.rb
+++ b/spec/dummy/config/environments/test.rb
@@ -30,7 +30,7 @@ Dummy::Application.configure do
config.action_mailer.delivery_method = :test
# Raise exception on mass assignment protection for Active Record models
- config.active_record.mass_assignment_sanitizer = :strict
+ # config.active_record.mass_assignment_sanitizer = :strict
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
diff --git a/spec/dummy/config/initializers/devise.rb b/spec/dummy/config/initializers/devise.rb
new file mode 100644
index 0000000..eff990e
--- /dev/null
+++ b/spec/dummy/config/initializers/devise.rb
@@ -0,0 +1,223 @@
+# Use this hook to configure devise mailer, warden hooks and so forth.
+# Many of these configuration options can be set straight in your model.
+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"
+
+ # Configure the class responsible to send e-mails.
+ # config.mailer = "Devise::Mailer"
+
+ # Automatically apply schema changes in tableless databases
+ config.apply_schema = false
+
+ # ==> ORM configuration
+ # Load and configure the ORM. Supports :active_record (default) and
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
+ # available as additional gems.
+ # require 'devise/orm/'
+
+ # ==> Configuration for any authentication mechanism
+ # Configure which keys are used when authenticating a user. The default is
+ # just :email. You can configure it to use [:username, :subdomain], so for
+ # authenticating a user, both parameters are required. Remember that those
+ # parameters are used only when authenticating and not when retrieving from
+ # session. If you need permissions, you should implement that in a before filter.
+ # You can also supply a hash where the value is a boolean determining whether
+ # or not authentication should be aborted when the value is not present.
+ # config.authentication_keys = [ :email ]
+
+ # Configure parameters from the request object used for authentication. Each entry
+ # given should be a request method and it will automatically be passed to the
+ # find_for_authentication method and considered in your model lookup. For instance,
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
+ # config.request_keys = []
+
+ # Configure which authentication keys should be case-insensitive.
+ # These keys will be downcased upon creating or modifying a user and when used
+ # to authenticate or find a user. Default is :email.
+ config.case_insensitive_keys = [ :email ]
+
+ # Configure which authentication keys should have whitespace stripped.
+ # These keys will have whitespace before and after removed upon creating or
+ # modifying a user and when used to authenticate or find a user. Default is :email.
+ config.strip_whitespace_keys = [ :email ]
+
+ # Tell if authentication through request.params is enabled. True by default.
+ # It can be set to an array that will enable params authentication only for the
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
+ # enable it only for database (email + password) authentication.
+ # config.params_authenticatable = true
+
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
+ # It can be set to an array that will enable http authentication only for the
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
+ # enable it only for token authentication.
+ # config.http_authenticatable = false
+
+ # If http headers should be returned for AJAX requests. True by default.
+ # config.http_authenticatable_on_xhr = true
+
+ # The realm used in Http Basic Authentication. "Application" by default.
+ # config.http_authentication_realm = "Application"
+
+ # It will change confirmation, password recovery and other workflows
+ # to behave the same regardless if the e-mail provided was right or wrong.
+ # Does not affect registerable.
+ # config.paranoid = true
+
+ # By default Devise will store the user in session. You can skip storage for
+ # :http_auth and :token_auth by adding those symbols to the array below.
+ # Notice that if you are skipping storage for all authentication paths, you
+ # may want to disable generating routes to Devise's sessions controller by
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
+ config.skip_session_storage = [:http_auth]
+
+ # ==> Configuration for :database_authenticatable
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
+ # using other encryptors, it sets how many times you want the password re-encrypted.
+ #
+ # Limiting the stretches to just one in testing will increase the performance of
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
+ # a value less than 10 in other environments.
+ config.stretches = Rails.env.test? ? 1 : 10
+
+ # Setup a pepper to generate the encrypted password.
+ # config.pepper = "4d61ec240ec1a40b14433880885d34d96c937689a2756f88a65895640e20e69275ec4252b6c4b2d34a6cad3368a9f04b25221d02d230163ae50b4ff7d6ac0257"
+
+ # ==> Configuration for :confirmable
+ # A period that the user is allowed to access the website even without
+ # confirming his account. For instance, if set to 2.days, the user will be
+ # able to access the website for two days without confirming his account,
+ # access will be blocked just in the third day. Default is 0.days, meaning
+ # the user cannot access the website without confirming his account.
+ # config.allow_unconfirmed_access_for = 2.days
+
+ # If true, requires any email changes to be confirmed (exctly the same way as
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
+ # db field (see migrations). Until confirmed new email is stored in
+ # unconfirmed email column, and copied to email column on successful confirmation.
+ config.reconfirmable = true
+
+ # Defines which key will be used when confirming an account
+ # config.confirmation_keys = [ :email ]
+
+ # ==> Configuration for :rememberable
+ # The time the user will be remembered without asking for credentials again.
+ # config.remember_for = 2.weeks
+
+ # If true, extends the user's remember period when remembered via cookie.
+ # config.extend_remember_period = false
+
+ # If true, uses the password salt as remember token. This should be turned
+ # to false if you are not using database authenticatable.
+ config.use_salt_as_remember_token = true
+
+ # Options to be passed to the created cookie. For instance, you can set
+ # :secure => true in order to force SSL only cookies.
+ # config.cookie_options = {}
+
+ # ==> Configuration for :validatable
+ # Range for password length. Default is 6..128.
+ # config.password_length = 6..128
+
+ # Email regex used to validate email formats. It simply asserts that
+ # an one (and only one) @ exists in the given string. This is mainly
+ # to give user feedback and not to assert the e-mail validity.
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
+
+ # ==> Configuration for :timeoutable
+ # The time you want to timeout the user session without activity. After this
+ # time the user will be asked for credentials again. Default is 30 minutes.
+ # config.timeout_in = 30.minutes
+
+ # ==> Configuration for :lockable
+ # Defines which strategy will be used to lock an account.
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
+ # :none = No lock strategy. You should handle locking by yourself.
+ # config.lock_strategy = :failed_attempts
+
+ # Defines which key will be used when locking and unlocking an account
+ # config.unlock_keys = [ :email ]
+
+ # Defines which strategy will be used to unlock an account.
+ # :email = Sends an unlock link to the user email
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
+ # :both = Enables both strategies
+ # :none = No unlock strategy. You should handle unlocking by yourself.
+ # config.unlock_strategy = :both
+
+ # Number of authentication tries before locking an account if lock_strategy
+ # is failed attempts.
+ # config.maximum_attempts = 20
+
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
+ # config.unlock_in = 1.hour
+
+ # ==> Configuration for :recoverable
+ #
+ # Defines which key will be used when recovering the password for an account
+ # config.reset_password_keys = [ :email ]
+
+ # Time interval you can reset your password with a reset password key.
+ # Don't put a too small interval or your users won't have the time to
+ # change their passwords.
+ config.reset_password_within = 6.hours
+
+ # ==> Configuration for :encryptable
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
+ # REST_AUTH_SITE_KEY to pepper)
+ # config.encryptor = :sha512
+
+ # ==> Configuration for :token_authenticatable
+ # Defines name of the authentication token params key
+ # config.token_authentication_key = :auth_token
+
+ # ==> Scopes configuration
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
+ # "users/sessions/new". It's turned off by default because it's slower if you
+ # are using only default views.
+ # config.scoped_views = false
+
+ # Configure the default scope given to Warden. By default it's the first
+ # devise role declared in your routes (usually :user).
+ # config.default_scope = :user
+
+ # Configure sign_out behavior.
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
+ # The default is true, which means any logout action will sign out all active scopes.
+ # config.sign_out_all_scopes = true
+
+ # ==> Navigation configuration
+ # Lists the formats that should be treated as navigational. Formats like
+ # :html, should redirect to the sign in page when the user does not have
+ # access, but formats like :xml or :json, should return 401.
+ #
+ # If you have any extra navigational formats, like :iphone or :mobile, you
+ # should add them to the navigational formats lists.
+ #
+ # The "*/*" below is required to match Internet Explorer requests.
+ # config.navigational_formats = ["*/*", :html]
+
+ # The default HTTP method used to sign out a resource. Default is :delete.
+ config.sign_out_via = :delete
+
+ # ==> OmniAuth
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
+ # up on your models and hooks.
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
+
+ # ==> Warden configuration
+ # If you want to use other strategies, that are not supported by Devise, or
+ # change the failure app, you can configure them inside the config.warden block.
+ #
+ # config.warden do |manager|
+ # manager.intercept_401 = false
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
+ # end
+end
diff --git a/spec/dummy/config/locales/devise.en.yml b/spec/dummy/config/locales/devise.en.yml
new file mode 100644
index 0000000..73df488
--- /dev/null
+++ b/spec/dummy/config/locales/devise.en.yml
@@ -0,0 +1,57 @@
+# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
+
+en:
+ errors:
+ messages:
+ expired: "has expired, please request a new one"
+ not_found: "not found"
+ already_confirmed: "was already confirmed, please try signing in"
+ not_locked: "was not locked"
+ not_saved:
+ one: "1 error prohibited this %{resource} from being saved:"
+ other: "%{count} errors prohibited this %{resource} from being saved:"
+
+ devise:
+ failure:
+ already_authenticated: 'You are already signed in.'
+ unauthenticated: 'You need to sign in or sign up before continuing.'
+ unconfirmed: 'You have to confirm your account before continuing.'
+ locked: 'Your account is locked.'
+ invalid: 'Invalid email or password.'
+ invalid_token: 'Invalid authentication token.'
+ timeout: 'Your session expired, please sign in again to continue.'
+ inactive: 'Your account was not activated yet.'
+ sessions:
+ signed_in: 'Signed in successfully.'
+ signed_out: 'Signed out successfully.'
+ passwords:
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
+ updated: 'Your password was changed successfully. You are now signed in.'
+ updated_not_active: 'Your password was changed successfully.'
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
+ confirmations:
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
+ send_paranoid_instructions: 'If your e-mail exists on our database, 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.'
+ registrations:
+ signed_up: 'Welcome! You have signed up successfully.'
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
+ updated: 'You updated your account successfully.'
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
+ unlocks:
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
+ omniauth_callbacks:
+ success: 'Successfully authorized from %{kind} account.'
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
+ mailer:
+ confirmation_instructions:
+ subject: 'Confirmation instructions'
+ reset_password_instructions:
+ subject: 'Reset password instructions'
+ unlock_instructions:
+ subject: 'Unlock Instructions'
diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb
index 5153bc0..e1a7637 100644
--- a/spec/dummy/config/routes.rb
+++ b/spec/dummy/config/routes.rb
@@ -1,8 +1,8 @@
Rails.application.routes.draw do
devise_for :users, :controllers => {:sessions => 'cmtool/sessions', :passwords => 'cmtool/passwords'}
+ mount Cmtool::Engine => "/cmtool"
match "/:name" => "pages#show"
match "/*url" => "pages#not_found"
root :to => 'pages#home'
- mount Cmtool::Engine => "/cmtool"
end
diff --git a/spec/factories/faq_factory.rb b/spec/factories/faq_factory.rb
new file mode 100644
index 0000000..cf94bc9
--- /dev/null
+++ b/spec/factories/faq_factory.rb
@@ -0,0 +1,4 @@
+FactoryGirl.define do
+ factory :faq, class: Cmtool::Faq do
+ end
+end
diff --git a/spec/factories/newsletter_subscription_factory.rb b/spec/factories/newsletter_subscription_factory.rb
new file mode 100644
index 0000000..b8ce1ee
--- /dev/null
+++ b/spec/factories/newsletter_subscription_factory.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :newsletter_subscription, class: Cmtool::NewsletterSubscription do
+ sequence(:created_at){|i| Time.zone.now + i.seconds} # ensure following created at
+ sequence(:email){ |i| "subscriber#{i}@example.com" }
+ end
+end
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
new file mode 100644
index 0000000..c22c79d
--- /dev/null
+++ b/spec/factories/user_factory.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :user, class: User do
+ email 'utools-test@example.com'
+ password '12345'
+ is_admin true
+ active true
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e66d980..324914a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,14 +1,55 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
-ENV["RAILS_ENV"] ||= 'test'
-require File.expand_path("../../config/environment", __FILE__)
+ENV["RAILS_ENV"] = "test"
+require File.expand_path("../dummy/config/environment.rb", __FILE__)
+
require 'rspec/rails'
require 'rspec/autorun'
+require 'factory_girl'
+require 'capybara/rspec'
+ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
+Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f }
+I18n.locale = :en
+Devise.stretches = 1
+Capybara.default_driver = :selenium
RSpec.configure do |config|
+ config.mock_with :rspec
+ config.include FactoryGirl::Syntax::Methods
+ #config.include CompanyFactory
+ config.include Cmtool::Engine.routes.url_helpers
+ config.include Devise::TestHelpers, :type => :controller
+ #config.use_transactional_fixtures = true
+ config.infer_base_class_for_anonymous_controllers = true
+ config.render_views = true
+
+ config.before :each do
+ CouchPotato.couchrest_database.recreate!
+ @user = User.first || create(:user)
+ end
+
+ config.before :all, type: :controller do
+ #render_views
+ end
+
+ config.before :all do
+ end
+ config.before :each, type: :request do
+ #Capybara.current_driver = :selenium
+ sign_in_user_through_request
+ end
+ config.after :each, type: :request do
+ visit "/users/sign_out"
+ end
+ def sign_in_user_through_request
+ visit "/users/sign_in"
+ fill_in 'user[email]', with: @user.email
+ fill_in 'user[password]', with: @user.password
+ click_on 'Sign in'
+ end
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
@@ -18,12 +59,12 @@ RSpec.configure do |config|
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
- config.use_transactional_fixtures = true
+ #config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of