Permalink
Browse files

Akriti/Sumedha: Fixed the radio button label. Added handling of empty…

… users employers list as well as friends employers list.
  • Loading branch information...
1 parent 0a14a02 commit 8f389170bf76479c417352ccc646ae056a862e5c @akritiayu akritiayu committed Mar 4, 2013
@@ -7,6 +7,9 @@ def index
def employers
begin
@employers = my_employers
+ if @employers.empty?
+ render :no_employers
+ end
rescue Exception => ex
render json: { message: "You are probably not logged in" }, status: :not_found
end
@@ -15,6 +18,9 @@ def employers
def change_employer
begin
@employers = friends_employers
+ if @employers.empty?
+ render :no_friends_employers
+ end
rescue Exception => ex
render json: { message: "You are probably not logged in" }, status: :not_found
end
@@ -6,4 +6,4 @@
%td{width: '25px'}
= radio_button_tag 'compId', employer_id
%td
- = label_tag "employer_#{employer_id}", employer_name
+ = label_tag "compId_#{employer_id}", employer_name
@@ -0,0 +1,3 @@
+= javascript_include_tag 'widget/employers'
+.employers
+ Oops! Looks like you have no employers listed in your Facebook profile
@@ -0,0 +1,2 @@
+= javascript_include_tag 'widget/no_employers'
+Oops! Looks like your friends have not listed any employers on their Facebook profile
@@ -31,9 +31,9 @@ def my_employers
def friends_employers
Rails.cache.fetch("friends_for_#{self.facebook_access_token}", :expires_in => 1.hour) do
employers = Hash.new(0)
- FbGraph::Query.new('select uid, name, work.employer from user where uid in (select uid2 from friend where uid1=me())').
+ FbGraph::Query.new('SELECT uid, name, work.employer FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND work.employer').
fetch(self.facebook_access_token).each do|f|
- employers[f[:work][0][:employer]] += 1 if !f[:work].empty?
+ employers[f[:work][0][:employer]] += 1
end
Hash[employers.sort {|a,b| b[1]<=>a[1]}].keys[0..4]
end
@@ -43,7 +43,7 @@ def facebook_friends(compId)
Rails.cache.fetch("friends_for_#{self.facebook_access_token}_at_#{compId}", :expires_in => 1.hour) do
friends = {}
if(compId != nil)
- FbGraph::Query.new('select uid, name, work.employer.id from user where uid in (select uid2 from friend where uid1=me())').
+ FbGraph::Query.new('SELECT uid, name, work.employer.id FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())').
fetch(self.facebook_access_token).each do|f|
if(f[:work].collect {|a| a[:employer]}.collect {|a| a[:id]}.include?(compId))
friends[f[:uid].to_s] = { id: f[:uid], name: f[:name] }
@@ -23,7 +23,7 @@
response.body.should == friends.to_json
end
- it "should return friend list" do
+ it "should return friend list with CompId" do
friends = [{ id: "1", name: "test"}]
controller.should_receive(:facebook_friends_for_link).with('http://google.com/', 1234) { friends }
@@ -51,6 +51,7 @@
get :employers
response.should be_successful
+ response.should render_template "facebook_share_widget/facebook/employers"
assigns(:employers).to_json.should == employers.to_json
end
@@ -63,6 +64,16 @@
response.should_not be_successful
response.body.should == { message: "You are probably not logged in" }.to_json
end
+
+ it "should return no employers message when no employers are listed" do
+ employers = []
+ controller.should_receive(:my_employers) { employers }
+
+ get :employers
+
+ response.should be_successful
+ response.should render_template "facebook_share_widget/facebook/no_employers"
+ end
end
describe "#share" do
context "successful post" do
@@ -105,7 +116,18 @@
get :change_employer
response.should be_successful
+ response.should render_template "facebook_share_widget/facebook/change_employer"
assigns(:employers).to_json.should == employers.to_json
end
+
+ it "should return no employers message when no friends' employers are found" do
+ employers = []
+ controller.should_receive(:friends_employers) { employers }
+
+ get :change_employer
+
+ response.should be_successful
+ response.should render_template "facebook_share_widget/facebook/no_friends_employers"
+ end
end
end

0 comments on commit 8f38917

Please sign in to comment.