Skip to content

Commit

Permalink
Added tests for sync plans
Browse files Browse the repository at this point in the history
  • Loading branch information
parthaa committed Aug 29, 2011
1 parent 082501e commit 4e2cf3c
Showing 1 changed file with 171 additions and 137 deletions.
308 changes: 171 additions & 137 deletions src/spec/controllers/sync_plans_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,148 +5,182 @@
include LoginHelperMethods
include LocaleHelperMethods
include OrganizationHelperMethods
include AuthorizationHelperMethods

before (:each) do
login_user
set_default_locale

@org = new_test_org
controller.stub!(:current_organization).and_return(@org)
end
let(:plan_create) do
{
:sync_plan => {
:name => 'myplan',
:interval => 'weekly',
:plan_date =>'01/01/11',
:plan_time => '07:00 am',
:description => 'RSPEC me'
}
}
end

describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end

describe "Create a SyncPlan" do

it "should create a plan successfully" do
controller.should_receive(:notice)
post :create, plan_create
SyncPlan.first.should_not be_nil
response.should be_success
end

it "should have a valid date" do
controller.should_receive(:errors)
plan_create[:sync_plan].should_not be_nil
data = plan_create
data[:sync_plan][:plan_date] = '01/101/11'
post :create, data
SyncPlan.first.should be_nil
response.should_not be_success
end

it "should have a unique name" do
controller.should_receive(:errors)
SyncPlan.create! :name => 'myplan', :interval => 'weekly', :sync_date => DateTime.now, :organization => controller.current_organization
SyncPlan.first.should_not be_nil
post :create, plan_create
response.should_not be_success
end

it "should not have a nil name" do
controller.should_receive(:errors)
data = plan_create
data[:sync_plan][:name] = ''
post :create, data
SyncPlan.first.should be_nil
response.should_not be_success
end

end

describe "Delete a SyncPlan" do
it "should delete a sync plan successfully" do
plan = SyncPlan.create! :name => 'myplan', :interval => 'weekly', :sync_date => DateTime.now, :organization => controller.current_organization
controller.stub!(:render).and_return("") #ignore missing js partial
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
delete :destroy, :id => plan.id
describe "rules" do
before (:each) do
new_test_org
end
describe "GET index" do
before do
@provider = Provider.create!(:provider_type=>Provider::CUSTOM, :name=>"foo1", :organization=>@organization)
end
let(:action) {:index}
let(:req) { get :index}
let(:authorized_user) do
user_with_permissions { |u| u.can(:read, :providers, @provider.id, @organization) }
end
let(:unauthorized_user) do
user_without_permissions
end
it_should_behave_like "protected action"
end

describe "Manage test" do
let(:action) {:new}
let(:req) { get :new}
let(:authorized_user) do
user_with_permissions { |u| u.can(:sync, :organizations, nil, @organization) }
end
let(:unauthorized_user) do
user_without_permissions
end
it_should_behave_like "protected action"
end
end

describe "Update a SyncPlan" do
describe "other-tests" do
before (:each) do
@plan = SyncPlan.create! :name => 'myplan', :interval => 'weekly', :sync_date => DateTime.now, :organization => controller.current_organization
end

it "should update a sync plan name successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:name => 'yourplan'}
response.should be_success
end

it "should update a sync plan interval successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:interval => 'daily'}
response.should be_success
end

it "should update interval to none successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:interval => 'none'}
response.should be_success
end

it "should update a sync plan description successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:description => 'Would rather be fishing then writing tests'}
response.should be_success
end

it "should update a sync time description successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:time => '12:00 pm'}
response.should be_success
end

it "should update a sync date description successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:date => '11/11/11'}
response.should be_success
end

it "should not update bad sync dates" do
SyncPlan.first.should_not be_nil
controller.should_receive(:errors)
put :update, :id => @plan.id, :sync_plan => {:date => '11/111111/11'}
response.should_not be_success
end

it "should not update bad sync time" do
SyncPlan.first.should_not be_nil
controller.should_receive(:errors)
put :update, :id => @plan.id, :sync_plan => {:time => '30:00 pmm'}
response.should_not be_success
end

it "should not update a blank name" do
SyncPlan.first.should_not be_nil
controller.should_receive(:errors)
put :update, :id => @plan.id, :sync_plan => {:name => ''}
response.should_not be_success
login_user
set_default_locale

@org = new_test_org
controller.stub!(:current_organization).and_return(@org)
end
let(:plan_create) do
{
:sync_plan => {
:name => 'myplan',
:interval => 'weekly',
:plan_date =>'01/01/11',
:plan_time => '07:00 am',
:description => 'RSPEC me'
}
}
end

describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end

describe "Create a SyncPlan" do

it "should create a plan successfully" do
controller.should_receive(:notice)
post :create, plan_create
SyncPlan.first.should_not be_nil
response.should be_success
end

it "should have a valid date" do
controller.should_receive(:errors)
plan_create[:sync_plan].should_not be_nil
data = plan_create
data[:sync_plan][:plan_date] = '01/101/11'
post :create, data
SyncPlan.first.should be_nil
response.should_not be_success
end

it "should have a unique name" do
controller.should_receive(:errors)
SyncPlan.create! :name => 'myplan', :interval => 'weekly', :sync_date => DateTime.now, :organization => controller.current_organization
SyncPlan.first.should_not be_nil
post :create, plan_create
response.should_not be_success
end

it "should not have a nil name" do
controller.should_receive(:errors)
data = plan_create
data[:sync_plan][:name] = ''
post :create, data
SyncPlan.first.should be_nil
response.should_not be_success
end

end

describe "Delete a SyncPlan" do
it "should delete a sync plan successfully" do
plan = SyncPlan.create! :name => 'myplan', :interval => 'weekly', :sync_date => DateTime.now, :organization => controller.current_organization
controller.stub!(:render).and_return("") #ignore missing js partial
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
delete :destroy, :id => plan.id
end
end

describe "Update a SyncPlan" do
before (:each) do
@plan = SyncPlan.create! :name => 'myplan', :interval => 'weekly', :sync_date => DateTime.now, :organization => controller.current_organization
end

it "should update a sync plan name successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:name => 'yourplan'}
response.should be_success
end

it "should update a sync plan interval successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:interval => 'daily'}
response.should be_success
end

it "should update interval to none successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:interval => 'none'}
response.should be_success
end

it "should update a sync plan description successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:description => 'Would rather be fishing then writing tests'}
response.should be_success
end

it "should update a sync time description successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:time => '12:00 pm'}
response.should be_success
end

it "should update a sync date description successfully" do
SyncPlan.first.should_not be_nil
controller.should_receive(:notice)
put :update, :id => @plan.id, :sync_plan => {:date => '11/11/11'}
response.should be_success
end

it "should not update bad sync dates" do
SyncPlan.first.should_not be_nil
controller.should_receive(:errors)
put :update, :id => @plan.id, :sync_plan => {:date => '11/111111/11'}
response.should_not be_success
end

it "should not update bad sync time" do
SyncPlan.first.should_not be_nil
controller.should_receive(:errors)
put :update, :id => @plan.id, :sync_plan => {:time => '30:00 pmm'}
response.should_not be_success
end

it "should not update a blank name" do
SyncPlan.first.should_not be_nil
controller.should_receive(:errors)
put :update, :id => @plan.id, :sync_plan => {:name => ''}
response.should_not be_success
end
end
end

end

0 comments on commit 4e2cf3c

Please sign in to comment.