diff --git a/Gemfile b/Gemfile index 43dceb3ff..73325d81d 100644 --- a/Gemfile +++ b/Gemfile @@ -41,10 +41,8 @@ gem 'ckeditor' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' - # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'rspec-rails', '~> 3.0' @@ -52,6 +50,7 @@ group :development, :test do gem 'factory_girl_rails' gem 'launchy' gem 'quiet_assets' + gem 'letter_opener_web', '~> 1.2.0' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 675d3d304..9dad0c3ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,11 @@ GEM json (1.8.3) launchy (2.4.3) addressable (~> 2.3) + letter_opener (1.4.1) + launchy (~> 2.2) + letter_opener_web (1.2.3) + letter_opener (~> 1.0) + rails (>= 3.2) loofah (2.0.2) nokogiri (>= 1.5.9) mail (2.6.3) @@ -234,6 +239,7 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-rails launchy + letter_opener_web (~> 1.2.0) pg poltergeist quiet_assets @@ -247,3 +253,6 @@ DEPENDENCIES turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) + +BUNDLED WITH + 1.10.5 diff --git a/app/models/user.rb b/app/models/user.rb index 9c55bc59e..da1c3ab8d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ class User < ActiveRecord::Base - devise :database_authenticatable, :registerable, + devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable def name diff --git a/config/environments/development.rb b/config/environments/development.rb index e9d8fdb80..63168eb28 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -17,6 +17,9 @@ Rails.application.configure do config.action_mailer.raise_delivery_errors = false config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Deliver emails to a development mailbox at /letter_opener + config.action_mailer.delivery_method = :letter_opener + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08b2..34034499f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -30,6 +30,10 @@ Rails.application.configure do # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.action_mailer.default_url_options = { + host: 'test' + } + config.action_mailer.asset_host = 'http://madrid.test' # Randomize the order test cases are executed. config.active_support.test_order = :random diff --git a/config/routes.rb b/config/routes.rb index f5afd988c..cd95b8461 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,4 +61,8 @@ Rails.application.routes.draw do # # (app/controllers/admin/products_controller.rb) # resources :products # end + + if Rails.env.development? + mount LetterOpenerWeb::Engine, at: "/letter_opener" + end end diff --git a/db/migrate/20150731110702_add_confirmable_to_devise_for_users.rb b/db/migrate/20150731110702_add_confirmable_to_devise_for_users.rb new file mode 100644 index 000000000..c6b4310e6 --- /dev/null +++ b/db/migrate/20150731110702_add_confirmable_to_devise_for_users.rb @@ -0,0 +1,13 @@ +class AddConfirmableToDeviseForUsers < ActiveRecord::Migration + def change + # Confirmable + add_column :users, :confirmation_token, :string + add_column :users, :confirmed_at, :datetime + add_column :users, :confirmation_sent_at, :datetime + + # Reconfirmable + add_column :users, :unconfirmed_email, :string + + add_index :users, :confirmation_token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 1a32c61a7..237be8c85 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150718091702) do +ActiveRecord::Schema.define(version: 20150731110702) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" create_table "comments", force: :cascade do |t| t.integer "commentable_id" @@ -27,8 +30,8 @@ ActiveRecord::Schema.define(version: 20150718091702) do t.datetime "updated_at" end - add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type" - add_index "comments", ["user_id"], name: "index_comments_on_user_id" + add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type", using: :btree + add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree create_table "debates", force: :cascade do |t| t.string "title" @@ -48,15 +51,15 @@ ActiveRecord::Schema.define(version: 20150718091702) do t.datetime "created_at" end - add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id" - add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" + add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id", using: :btree + add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "tags", force: :cascade do |t| t.string "name" t.integer "taggings_count", default: 0 end - add_index "tags", ["name"], name: "index_tags_on_name", unique: true + add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree create_table "users", force: :cascade do |t| t.string "email", default: "", null: false @@ -73,10 +76,15 @@ ActiveRecord::Schema.define(version: 20150718091702) do t.datetime "updated_at", null: false t.string "first_name" t.string "last_name" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" end - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "votes", force: :cascade do |t| t.integer "votable_id" @@ -90,7 +98,7 @@ ActiveRecord::Schema.define(version: 20150718091702) do t.datetime "updated_at" end - add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope" - add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope" + add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree + add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree end diff --git a/spec/factories.rb b/spec/factories.rb index 9e9ab2d0a..65315a112 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -5,6 +5,7 @@ FactoryGirl.define do last_name 'Carmena' sequence(:email) { |n| "manuela#{n}@madrid.es" } password 'judgmentday' + confirmed_at { Time.now } end factory :debate do @@ -19,7 +20,7 @@ FactoryGirl.define do association :voter, factory: :user vote_flag true end - + factory :comment do commentable user diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 2d972e87f..92f30ea91 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -14,7 +14,7 @@ feature 'Users' do click_button 'Sign up' - expect(page).to have_content 'Welcome! You have signed up successfully.' + expect(page).to have_content "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." end scenario 'Sign in' do