Created
November 24, 2010 21:55
-
-
Save santiago/714504 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def score | |
resp = [] | |
begin | |
current_partner.nsbg.update({:need_id => params[:need_id], :score => params[:score]}) | |
rescue => e | |
resp = {:error => e.message} | |
end | |
respond_to do |format| | |
format.json { render :json => resp } | |
end | |
end | |
def priority | |
resp = [] | |
begin | |
current_partner.nsbg.update_priority params[:need_id], params[:priority] | |
rescue => e | |
resp = {:error => e.message} | |
end | |
respond_to do |format| | |
format.json { render :json => resp } | |
end | |
end | |
def hidden | |
resp = [] | |
begin | |
current_partner.nsbg.update_visibility({:need_id => params[:need_id], :hidden => Util.to_boolean(params[:hidden])}) | |
rescue => e | |
resp = {:error => e.message} | |
end | |
respond_to do |format| | |
format.json { render :json => resp } | |
end | |
end | |
def share | |
resp = [] | |
begin | |
current_partner.nsbg.share_changes | |
rescue => e | |
resp = {:error => e.message} | |
end | |
respond_to do |format| | |
format.json { render :json => resp } | |
end | |
end | |
This file contains hidden or 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 File.join('spec', 'spec_helper') | |
describe NsbgsController do | |
before(:each) do | |
@partner= Factory.stub(:partner) | |
@nsbg= mock("nsbg") | |
@partner.stub(:nsbg).and_return(@nsbg) | |
controller.stub(:current_partner).and_return(@partner) | |
end | |
describe "#score" do | |
it "should update Need in NSBG with new score and respond JSON []" do | |
# nsbg= mock("nsbg") | |
# @partner.stub(:nsbg).and_return(nsbg) | |
@nsbg.should_receive(:update) | |
post :score | |
JSON.parse(response.body).should == [] | |
end | |
it "should respond JSON with error if can't perform update" do | |
post :score | |
JSON.parse(response.body)['error'].should_not be_nil | |
end | |
end | |
describe "#priority" do | |
it "should update Need in NSBG with new priority and respond JSON []" do | |
nsbg= mock("nsbg") | |
@partner.stub(:nsbg).and_return(nsbg) | |
nsbg.should_receive(:update_priority) | |
post :priority | |
JSON.parse(response.body).should == [] | |
end | |
it "should respond JSON with error if can't perform update" do | |
post :priority | |
JSON.parse(response.body)['error'].should_not be_nil | |
end | |
end | |
describe "#hidden" do | |
it "should hide Need in NSBG and respond JSON []" do | |
nsbg= mock("nsbg") | |
@partner.stub(:nsbg).and_return(nsbg) | |
nsbg.should_receive(:update_visibility) | |
post :hidden | |
JSON.parse(response.body).should == [] | |
end | |
it "should respond JSON with error if can't perform update" do | |
post :hidden | |
JSON.parse(response.body)['error'].should_not be_nil | |
end | |
end | |
describe "#share" do | |
it "should share changes in NSBG and respond JSON []" do | |
nsbg= mock("nsbg") | |
@partner.stub(:nsbg).and_return(nsbg) | |
nsbg.should_receive(:share_changes) | |
post :share | |
JSON.parse(response.body).should == [] | |
end | |
it "should respond JSON with error if can't perform update" do | |
post :share | |
JSON.parse(response.body)['error'].should_not be_nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment