]> git.openstreetmap.org Git - rails.git/blobdiff - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_token_spec.rb
Adding initial version of the OAuth token authentication method. This adds basic...
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / oauth_token_spec.rb
diff --git a/vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_token_spec.rb b/vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_token_spec.rb
new file mode 100644 (file)
index 0000000..594c204
--- /dev/null
@@ -0,0 +1,55 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe RequestToken do
+  fixtures :client_applications, :users, :oauth_tokens
+  before(:each) do
+    @token = RequestToken.create :client_application => client_applications(:one)
+  end
+
+  it "should be valid" do
+    @token.should be_valid
+  end
+  
+  it "should not have errors" do
+    @token.errors.should_not == []
+  end
+  
+  it "should have a token" do
+    @token.token.should_not be_nil
+  end
+
+  it "should have a secret" do
+    @token.secret.should_not be_nil
+  end
+  
+  it "should not be authorized" do 
+    @token.should_not be_authorized
+  end
+
+  it "should not be invalidated" do
+    @token.should_not be_invalidated
+  end
+  
+  it "should authorize request" do
+    @token.authorize!(users(:quentin))
+    @token.should be_authorized
+    @token.authorized_at.should_not be_nil
+    @token.user.should == users(:quentin)
+  end
+  
+  it "should not exchange without approval" do
+    @token.exchange!.should == false
+    @token.should_not be_invalidated
+  end
+  
+  it "should not exchange without approval" do
+    @token.authorize!(users(:quentin))
+    @access = @token.exchange!
+    @access.should_not == false
+    @token.should be_invalidated
+    
+    @access.user.should == users(:quentin)
+    @access.should be_authorized
+  end
+  
+end