Last active
December 14, 2015 01:39
-
-
Save shepmaster/5007887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Api::V1_2::TokensController do | |
def parsed_response(response) | |
JSON.parse(response.body) | |
end | |
describe "POST create" do | |
let(:params) { {} } | |
let(:user) { Factory(:confirmed_user_with_account) } | |
before(:each) do | |
# headers isn't defined here? | |
post api_1_2_tokens_path, params, @headers | |
end | |
context "with no credentials" do | |
it "responds with unauthorized" do | |
response.code.should == '401' | |
end | |
end | |
context "with bad credentials" do | |
let(:params) { {:email => user.email, :password => "thisitnotthe#{user.password}"} } | |
it "responds with unauthorized" do | |
response.code.should == '401' | |
end | |
end | |
context "with proper credentials" do | |
let(:params) { {:email => user.email, :password => user.password} } | |
it "responds with 200" do | |
response.code.should == '200' | |
end | |
it "returns a token" do | |
subject[:token].should == @user.reload.authentication_token | |
end | |
context "when the user does not have a token" do | |
# Change the user first | |
let(:user) { Factory(:confirmed_user_with_account_without_token) } | |
subject do | |
parsed_response(response) | |
end | |
it "generates one" do | |
subject[:token].should be | |
end | |
end | |
context "when the user already has a token" do | |
before(:each) do | |
user.ensure_authentication_token! | |
@old_token = user.authentication_token | |
end | |
subject do | |
parsed_response(response) | |
end | |
it "generates a new one" do | |
subject[:token].should_not == @old_token | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment