describe DesignsController, "#index project sort" do

before(:each) do
login_with(:view_own_designs)
end

describe "with project sort parameter" do

before(:each) do
@cookies = {}
controller.stub!(:cookies).and_return(@cookies)
end

def get_index
get :index, :project_sort => "name"
end

it "sets a cookie with the value and new expiration date" do
get_index
@cookies[:project_sort][:value].should == "name"
@cookies[:project_sort][:expires].beginning_of_day.should == 1.year.from_now.beginning_of_day
end

it "captures the value for the view" do
get_index
assigns[:project_sort].should == "name"
end

end

describe "without project sort parameter" do

def get_index
get :index
end

describe "without existing cookie" do

before(:each) do
@cookies = {}
controller.stub!(:cookies).and_return(@cookies)
end

it "sets a cookie with the default value and new expiration date" do
get_index
@cookies[:project_sort][:value].should == "created_at"
@cookies[:project_sort][:expires].beginning_of_day.should == 1.year.from_now.beginning_of_day
end

it "captures the value for the view" do
get_index
assigns[:project_sort].should == "created_at"
end

end

describe "with existing cookie" do

before(:each) do
@cookies = { :project_sort => "name" }
controller.stub!(:cookies).and_return(@cookies)
end

it "resets the cookie with the value and new expiration date" do
get_index
@cookies[:project_sort][:value].should == "name"
@cookies[:project_sort][:expires].beginning_of_day.should == 1.year.from_now.beginning_of_day
end

it "captures the value for the view" do
get_index
assigns[:project_sort].should == "name"
end

end

end

end