Fixing unsubscribe feature

This commit is contained in:
yafeilee 2016-04-27 16:12:56 +08:00
parent f543fad37d
commit 26eb22b895
4 changed files with 20 additions and 12 deletions

View File

@ -53,8 +53,6 @@ group :development do
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'byebug'
gem 'rack-cors', :require => 'rack/cors'
end
@ -68,7 +66,6 @@ end
group :test, :development do
gem "rspec-rails", ">= 2.8.1"
gem 'rails-controller-testing'
gem 'pry-rails'
gem 'pry-nav'
gem 'byebug'
gem 'factory_girl_rails'
end

View File

@ -181,10 +181,6 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-nav (0.2.4)
pry (>= 0.9.10, < 0.11.0)
pry-rails (0.3.4)
pry (>= 0.9.10)
puma (3.4.0)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
@ -363,8 +359,6 @@ DEPENDENCIES
newrelic_rpm
nokogiri
pg
pry-nav
pry-rails
puma
quiet_assets
rack-cors

View File

@ -7,11 +7,15 @@ class UnsubscribesController < ApplicationController
end
def create
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
subscribe = Subscribe.find_or_initialize_by(email: subscribe_params[:email])
subscribe.enable = false
subscribe.save
flash[:notice] = "退订成功: #{params[:email]}"
flash[:notice] = "退订成功: #{subscribe_params[:email]}"
redirect_to unsubscribes_path
end
def subscribe_params
params.require(:subscribe).permit(:email)
end
end

View File

@ -0,0 +1,13 @@
require 'spec_helper'
describe UnsubscribesController do
describe "POST 'create'" do
it "unsuscribe ok" do
subscribe = create(:subscribe, enable: true)
post 'create', { subscribe: { email: subscribe.email } }
expect(subscribe.reload.enable).to be(false)
end
end
end