Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Pass flag to allow multiple actions per campaign/page
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Aug 4, 2016
1 parent 730688b commit b43cc45
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
12 changes: 11 additions & 1 deletion app/services/manage_action.rb
@@ -1,5 +1,6 @@
class ManageAction
include ActionBuilder
attr_reader :params

def self.create(params)
new(params).create
Expand All @@ -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
@@ -0,0 +1,5 @@
class AddAllowDuplicateActionsToPage < ActiveRecord::Migration
def change
add_column :pages, :allow_duplicate_actions, :boolean, default: false
end
end
29 changes: 25 additions & 4 deletions db/schema.rb
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions spec/requests/api/actions_spec.rb
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/services/manage_action_spec.rb
Expand Up @@ -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

0 comments on commit b43cc45

Please sign in to comment.