spec/urbanairship_spec.rb in urbanairship-1.1.1 vs spec/urbanairship_spec.rb in urbanairship-2.0.0
- old
+ new
@@ -33,20 +33,10 @@
# feedback
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/feedback/, :status => ["200", "OK"], :body => "[{\"device_token\":\"token\",\"marked_inactive_on\":\"2010-10-14T19:15:13Z\",\"alias\":\"my_alias\"}]")
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/feedback/, :status => ["500", "Internal Server Error"])
end
- after(:each) do
- # reset configuration
- Urbanairship.application_key = nil
- Urbanairship.application_secret = nil
- Urbanairship.master_secret = nil
- Urbanairship.logger = nil
-
- FakeWeb.instance_variable_set("@last_request", nil)
- end
-
describe "configuration" do
it "enables you to configure the application key" do
Urbanairship.application_key.should be_nil
Urbanairship.application_key = "asdf1234"
Urbanairship.application_key.should == "asdf1234"
@@ -90,36 +80,26 @@
Urbanairship.register_device("new_device_token")
FakeWeb.last_request.path.should == "/api/device_tokens/new_device_token"
end
it "returns true when the device is registered for the first time" do
- Urbanairship.register_device("new_device_token").should == true
+ Urbanairship.register_device("new_device_token").success?.should == true
end
it "returns true when the device is registered again" do
- Urbanairship.register_device("existing_device_token").should == true
+ Urbanairship.register_device("existing_device_token").success?.should == true
end
it "returns false when the authorization is invalid" do
Urbanairship.application_key = "bad_key"
- Urbanairship.register_device("new_device_token").should == false
+ Urbanairship.register_device("new_device_token").success?.should == false
end
- it "doesn't set the content-type header to application/json if options are empty" do
- Urbanairship.register_device("device_token_one")
- FakeWeb.last_request['content-type'].should_not == 'application/json'
- end
-
it "accepts an alias" do
- Urbanairship.register_device("device_token_one", @valid_params).should == true
+ Urbanairship.register_device("device_token_one", @valid_params).success?.should == true
end
- it "sets the content-type header to application/json when options are added" do
- Urbanairship.register_device("device_token_one", @valid_params)
- FakeWeb.last_request['content-type'].should == 'application/json'
- end
-
it "adds alias to the JSON payload" do
Urbanairship.register_device("device_token_one", @valid_params)
request_json['alias'].should == "one"
end
@@ -153,17 +133,17 @@
Urbanairship.unregister_device("key_to_delete")
FakeWeb.last_request.path.should == "/api/device_tokens/key_to_delete"
end
it "returns true when the device is successfully unregistered" do
- Urbanairship.unregister_device("key_to_delete").should == true
+ Urbanairship.unregister_device("key_to_delete").success?.should == true
FakeWeb.last_request.body.should be_nil
end
it "returns false when the authorization is invalid" do
Urbanairship.application_key = "bad_key"
- Urbanairship.unregister_device("key_to_delete").should == false
+ Urbanairship.unregister_device("key_to_delete").success?.should == false
end
end
describe "::delete_scheduled_push" do
before(:each) do
@@ -199,17 +179,17 @@
Urbanairship.delete_scheduled_push(:alias => "alias_to_delete")
FakeWeb.last_request.path.should == "/api/push/scheduled/alias/alias_to_delete"
end
it "returns true when the push notification is successfully deleted" do
- Urbanairship.delete_scheduled_push("123456789").should == true
+ Urbanairship.delete_scheduled_push("123456789").success?.should == true
FakeWeb.last_request.body.should be_nil
end
it "returns false when the authorization is invalid" do
Urbanairship.application_key = "bad_key"
- Urbanairship.delete_scheduled_push("123456789").should == false
+ Urbanairship.delete_scheduled_push("123456789").success?.should == false
end
end
describe "::push" do
before(:each) do
@@ -231,23 +211,18 @@
Urbanairship.push(@valid_params)
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
end
it "returns true when it successfully pushes a notification" do
- Urbanairship.push(@valid_params).should == true
+ Urbanairship.push(@valid_params).success?.should == true
end
it "returns false when the authorization is invalid" do
Urbanairship.application_key = "bad_key"
- Urbanairship.push(@valid_params).should == false
+ Urbanairship.push(@valid_params).success?.should == false
end
- it "sets the content-type header to application/json" do
- Urbanairship.push(@valid_params)
- FakeWeb.last_request['content-type'].should == 'application/json'
- end
-
it "adds schedule_for to the JSON payload" do
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
Urbanairship.push(@valid_params.merge(:schedule_for => [time]))
request_json['schedule_for'].should == ['2010-10-17T20:00:00Z']
end
@@ -258,11 +233,11 @@
end
it "returns false if urbanairship responds with a non-200 response" do
Urbanairship.application_key = "my_app_key2"
Urbanairship.master_secret = "my_master_secret2"
- Urbanairship.push.should == false
+ Urbanairship.push.success?.should == false
end
end
describe "::batch_push" do
before(:each) do
@@ -287,23 +262,18 @@
Urbanairship.batch_push(@valid_params)
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
end
it "returns true when it successfully pushes a notification" do
- Urbanairship.batch_push(@valid_params).should == true
+ Urbanairship.batch_push(@valid_params).success?.should == true
end
it "returns false when the authorization is invalid" do
Urbanairship.application_key = "bad_key"
- Urbanairship.batch_push(@valid_params).should == false
+ Urbanairship.batch_push(@valid_params).success?.should == false
end
- it "sets the content-type header to application/json" do
- Urbanairship.batch_push(@valid_params)
- FakeWeb.last_request['content-type'].should == 'application/json'
- end
-
it "adds schedule_for to the JSON payload" do
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
@valid_params[0].merge!(:schedule_for => [time])
Urbanairship.batch_push(@valid_params)
request_json[0]['schedule_for'].should == ['2010-10-17T20:00:00Z']
@@ -316,11 +286,11 @@
end
it "returns false if urbanairship responds with a non-200 response" do
Urbanairship.application_key = "my_app_key2"
Urbanairship.master_secret = "my_master_secret2"
- Urbanairship.batch_push.should == false
+ Urbanairship.batch_push.success?.should == false
end
end
describe "::broadcast_push" do
before(:each) do
@@ -342,23 +312,18 @@
Urbanairship.broadcast_push(@valid_params)
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
end
it "returns true when it successfully pushes a notification" do
- Urbanairship.broadcast_push(@valid_params).should == true
+ Urbanairship.broadcast_push(@valid_params).success?.should == true
end
it "returns false when the authorization is invalid" do
Urbanairship.application_key = "bad_key"
- Urbanairship.broadcast_push(@valid_params).should == false
+ Urbanairship.broadcast_push(@valid_params).success?.should == false
end
- it "sets the content-type header to application/json" do
- Urbanairship.broadcast_push(@valid_params)
- FakeWeb.last_request['content-type'].should == 'application/json'
- end
-
it "adds schedule_for to the JSON payload" do
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
@valid_params[:schedule_for] = [time]
Urbanairship.broadcast_push(@valid_params)
request_json['schedule_for'].should == ['2010-10-17T20:00:00Z']
@@ -371,11 +336,11 @@
end
it "returns false if urbanairship responds with a non-200 response" do
Urbanairship.application_key = "my_app_key2"
Urbanairship.master_secret = "my_master_secret2"
- Urbanairship.broadcast_push.should == false
+ Urbanairship.broadcast_push.success?.should == false
end
end
describe "::feedback" do
before(:each) do
@@ -409,20 +374,18 @@
FakeWeb.last_request.path.should include("2010-10-07T08:00:00Z")
end
it "returns an array of responses from the feedback API" do
response = Urbanairship.feedback(Time.now)
- response.class.should == Array
- response[0].keys.should include("device_token")
- response[0].keys.should include("marked_inactive_on")
- response[0].keys.should include("alias")
+ response[0].should include("device_token")
+ response[0].should include("marked_inactive_on")
+ response[0].should include("alias")
end
- it "returns false and doesn't parse JSON when the call doesn't return 200" do
+ it "success? is false when the call doesn't return 200" do
Urbanairship.application_key = "my_app_key2"
Urbanairship.master_secret = "my_master_secret2"
- JSON.should_not_receive(:parse)
- Urbanairship.feedback(Time.now).should == false
+ Urbanairship.feedback(Time.now).success?.should == false
end
end
describe "logging" do