From 26eb22b895e72c22501018656d1f734d3dcf2ca3 Mon Sep 17 00:00:00 2001 From: yafeilee Date: Wed, 27 Apr 2016 16:12:56 +0800 Subject: [PATCH] Fixing unsubscribe feature --- Gemfile | 5 +---- Gemfile.lock | 6 ------ app/controllers/unsubscribes_controller.rb | 8 ++++++-- spec/controllers/unsuscribes_controller_spec.rb | 13 +++++++++++++ 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 spec/controllers/unsuscribes_controller_spec.rb diff --git a/Gemfile b/Gemfile index 40681e4..b0c4ca3 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 30fd863..430eb18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/controllers/unsubscribes_controller.rb b/app/controllers/unsubscribes_controller.rb index 1bf268e..fc922ef 100644 --- a/app/controllers/unsubscribes_controller.rb +++ b/app/controllers/unsubscribes_controller.rb @@ -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 diff --git a/spec/controllers/unsuscribes_controller_spec.rb b/spec/controllers/unsuscribes_controller_spec.rb new file mode 100644 index 0000000..5708f04 --- /dev/null +++ b/spec/controllers/unsuscribes_controller_spec.rb @@ -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