Permalink
Browse files

add specs for keychain interaction

  • Loading branch information...
mordaroso committed May 9, 2012
1 parent f3a7787 commit c99c11d612123169c75adbce1674e466e351018a
Showing with 36 additions and 1 deletion.
  1. +6 −1 app/models/user.rb
  2. +30 −0 spec/models/user_spec.rb
View
@@ -13,7 +13,12 @@ def save
def load
self.username = @keychain.objectForKey KSecAttrAccount
- NSLog("username: #{username}")
self.password = @keychain.objectForKey KSecValueData
end
+
+ def reset
+ self.username = ''
+ self.password = ''
+ @keychain.resetKeychainItem
+ end
end
View
@@ -0,0 +1,30 @@
+describe "User" do
+ before do
+ @user = User.new
+ @user.username = 'Username'
+ @user.password = 'Secret'
+ @user.save
+ end
+
+ it "should save username and password" do
+ @user.username = 'New Username'
+ @user.password = 'New Secret'
+ @user.save
+
+ @user.username.should == 'New Username'
+ @user.password.should == 'New Secret'
+ end
+
+ it "should load username and password" do
+ @second_user_object = User.new
+ @user.username.should == 'Username'
+ @user.password.should == 'Secret'
+ end
+
+ it "should reset information" do
+ @user.reset
+ @user.load
+ @user.username.should == ''
+ @user.username.should == ''
+ end
+end

0 comments on commit c99c11d

Please sign in to comment.