test/subscriber_test.rb in createsend-4.1.2 vs test/subscriber_test.rb in createsend-5.0.0

- old
+ new

@@ -7,11 +7,11 @@ @subscriber = CreateSend::Subscriber.new @auth, @list_id, "subscriber@example.com" end should "get a subscriber by list id and email address" do email = "subscriber@example.com" - stub_get(@auth, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", "subscriber_details.json") + stub_get(@auth, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}&includetrackingpreference=false", "subscriber_details.json") subscriber = CreateSend::Subscriber.get @auth, @list_id, email subscriber.EmailAddress.should == email subscriber.Name.should == "Subscriber One" subscriber.Date.should == "2010-10-25 10:28:00" subscriber.State.should == "Active" @@ -19,47 +19,56 @@ subscriber.CustomFields.first.Key.should == 'website' subscriber.CustomFields.first.Value.should == 'http://example.com' subscriber.ReadsEmailWith.should == "Gmail" end + should "get a subscriber with track preference information" do + email = "subscriber@example.com" + stub_get(@auth, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}&includetrackingpreference=true", "subscriber_details_with_track_pref.json") + subscriber = CreateSend::Subscriber.get @auth, @list_id, email, true + subscriber.EmailAddress.should == email + subscriber.Name.should == "Subscriber One" + subscriber.ConsentToTrack == "Yes" + end + should "add a subscriber without custom fields" do stub_post(@auth, "subscribers/#{@list_id}.json", "add_subscriber.json") - email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", [], true + email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", [], true, "Yes" email_address.should == "subscriber@example.com" end should "add a subscriber with custom fields" do stub_post(@auth, "subscribers/#{@list_id}.json", "add_subscriber.json") custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ] - email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true + email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true, "Yes" email_address.should == "subscriber@example.com" end should "add a subscriber with custom fields including multi-option fields" do stub_post(@auth, "subscribers/#{@list_id}.json", "add_subscriber.json") custom_fields = [ { :Key => 'multioptionselectone', :Value => 'myoption' }, { :Key => 'multioptionselectmany', :Value => 'firstoption' }, { :Key => 'multioptionselectmany', :Value => 'secondoption' } ] - email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true + email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true, "Yes" email_address.should == "subscriber@example.com" end should "update a subscriber with custom fields" do email = "subscriber@example.com" new_email = "new_email_address@example.com" stub_put(@auth, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", nil) custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ] - @subscriber.update new_email, "Subscriber", custom_fields, true + @subscriber.update new_email, "Subscriber", custom_fields, true, "Yes" @subscriber.email_address.should == new_email end should "update a subscriber with custom fields including the clear option" do email = "subscriber@example.com" new_email = "new_email_address@example.com" stub_put(@auth, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", nil) custom_fields = [ { :Key => 'website', :Value => '', :Clear => true } ] - @subscriber.update new_email, "Subscriber", custom_fields, true + @subscriber.update new_email, "Subscriber", custom_fields, true, "No" @subscriber.email_address.should == new_email end should "import many subscribers at once" do stub_post(@auth, "subscribers/#{@list_id}/import.json", "import_subscribers.json") @@ -131,11 +140,11 @@ subscribers = [ { :EmailAddress => "example+1@example", :Name => "Example One" }, { :EmailAddress => "example+2@example.com", :Name => "Example Two" }, { :EmailAddress => "example+3@example.com", :Name => "Example Three" }, ] - lambda { import_result = CreateSend::Subscriber.import @auth, @list_id, subscribers, true - }.should raise_error(CreateSend::BadRequest) + lambda { import_result = CreateSend::Subscriber.import @auth, @list_id, subscribers, + true }.should raise_error(CreateSend::BadRequest) end should "unsubscribe a subscriber" do stub_post(@auth, "subscribers/#{@subscriber.list_id}/unsubscribe.json", nil) @subscriber.unsubscribe \ No newline at end of file