diff --git a/app/services/manage_action.rb b/app/services/manage_action.rb index 39a24998d2..5eeee98921 100644 --- a/app/services/manage_action.rb +++ b/app/services/manage_action.rb @@ -1,5 +1,6 @@ class ManageAction include ActionBuilder + attr_reader :params def self.create(params) new(params).create @@ -10,7 +11,16 @@ def initialize(params) end def create - return previous_action if previous_action.present? + unless page.allow_duplicate_actions? + return previous_action if previous_action.present? + end + build_action end + + private + + def page + @page ||= Page.find(params[:page_id]) + end end diff --git a/db/migrate/20160804170019_add_allow_duplicate_actions_to_page.rb b/db/migrate/20160804170019_add_allow_duplicate_actions_to_page.rb new file mode 100644 index 0000000000..14a4a2db23 --- /dev/null +++ b/db/migrate/20160804170019_add_allow_duplicate_actions_to_page.rb @@ -0,0 +1,5 @@ +class AddAllowDuplicateActionsToPage < ActiveRecord::Migration + def change + add_column :pages, :allow_duplicate_actions, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 58a759b31d..11a17aa251 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,8 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160802225328) do - +ActiveRecord::Schema.define(version: 20160804170019) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -157,6 +156,19 @@ t.datetime "updated_at", null: false end + create_table "member_authentications", force: :cascade do |t| + t.integer "member_id" + t.string "password_digest", null: false + t.string "facebook_uid" + t.string "facebook_token" + t.datetime "facebook_token_expiry" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "member_authentications", ["facebook_uid"], name: "index_member_authentications_on_facebook_uid", using: :btree + add_index "member_authentications", ["member_id"], name: "index_member_authentications_on_member_id", using: :btree + create_table "members", force: :cascade do |t| t.string "email" t.string "country" @@ -200,6 +212,7 @@ t.integer "publish_status", default: 1, null: false t.integer "optimizely_status", default: 0, null: false t.string "canonical_url" + t.boolean "allow_duplicate_actions", default: false end add_index "pages", ["campaign_id"], name: "index_pages_on_campaign_id", using: :btree @@ -235,9 +248,16 @@ create_table "payment_braintree_payment_methods", force: :cascade do |t| t.string "token" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "customer_id" + t.string "card_type" + t.string "bin" + t.string "cardholder_name" + t.string "last_4" + t.string "expiration_date" + t.string "instrument_type" + t.string "email" end add_index "payment_braintree_payment_methods", ["customer_id"], name: "braintree_customer_index", using: :btree @@ -519,6 +539,7 @@ add_foreign_key "actions", "pages" add_foreign_key "form_elements", "forms" add_foreign_key "links", "pages" + add_foreign_key "member_authentications", "members" add_foreign_key "pages", "campaigns" add_foreign_key "pages", "images", column: "primary_image_id" add_foreign_key "pages", "languages" diff --git a/spec/requests/api/actions_spec.rb b/spec/requests/api/actions_spec.rb index f41dfdb420..c4bc0c1266 100644 --- a/spec/requests/api/actions_spec.rb +++ b/spec/requests/api/actions_spec.rb @@ -119,6 +119,22 @@ end end + describe 'page allows duplicate actions' do + let!(:member) { create :member, actionkit_user_id: '7777', email: params[:email]} + + before do + page.update(allow_duplicate_actions: true) + end + + subject{ post "/api/pages/#{page.id}/actions", params } + + it 'creats an action if existing action on this page' do + create :action, member: member, page: page + expect{ subject }.to change{ Action.count } + end + end + + describe 'akid manipulation' do context 'new member' do before do diff --git a/spec/services/manage_action_spec.rb b/spec/services/manage_action_spec.rb index 9234c0f585..fe2b3e801b 100644 --- a/spec/services/manage_action_spec.rb +++ b/spec/services/manage_action_spec.rb @@ -135,6 +135,25 @@ subject end end + + context "page permits duplicate actions" do + before do + page.update(allow_duplicate_actions: true) + @action = ManageAction.create(data) + end + + it 'returns new action' do + expect(subject).not_to eq @action + expect(subject).to be_an(Action) + end + + it 'posts to queue' do + expect(ChampaignQueue).to receive(:push) + + subject + end + end + end end