Browse Source

now agents repond to credential method call, and specs

Umar M. Sheikh 11 years ago
parent
commit
dcffc71732

+ 4 - 0
app/models/agent.rb

@@ -59,6 +59,10 @@ class Agent < ActiveRecord::Base
     where(:type => type)
   }
 
+  def credential(name)
+    user.user_credentials.where(:credential_name => name).limit(1).first.credential_value rescue nil
+  end
+
   def check
     # Implement me in your subclass of Agent.
   end

+ 0 - 2
app/views/devise/registrations/edit.html.erb

@@ -1,4 +1,3 @@
-hello doctor
 <div class='container'>
   <div class='row'>
     <div class='span8 offset2'>
@@ -49,7 +48,6 @@ hello doctor
           <div class='form-actions'>
             <%= f.submit "Update", :class => "btn btn-primary" %>
           </div>
-          now the new stuff
           <div class="control-group">
             <%= f.fields_for(:user_credentials) do |uc| %>
               <%= render 'user_credential_fields', :f => uc %>

+ 8 - 0
spec/fixtures/user_credentials.yml

@@ -0,0 +1,8 @@
+bob_aws_key:
+  user: bob
+  credential_name: aws_key
+  credential_value: 2222222222
+bob_aws_secret:
+  user: bob
+  credential_name: aws_secret
+  credential_value: 1111111111

+ 11 - 1
spec/models/agent_spec.rb

@@ -27,6 +27,16 @@ describe Agent do
     end
   end
 
+  describe "credential" do
+    it "should return the value of the credential when credential is present" do
+      agents(:bob_weather_agent).credential("aws_secret").should == user_credentials(:bob_aws_secret).credential_value
+    end
+
+    it "should return nil when credential is not present" do
+      agents(:bob_weather_agent).credential("non_existing_credential").should == nil
+    end
+  end
+
   describe "changes to type" do
     it "validates types" do
       source = Agent.new
@@ -473,4 +483,4 @@ describe Agent do
       end
     end
   end
-end
+end