Skip to content

Commit

Permalink
Added system_helper_methods for spec testing that mocks the backend
Browse files Browse the repository at this point in the history
Candlepin:Consumer call to allow for controller testing against
ActiveRecord.
  • Loading branch information
ehelms committed Jun 16, 2011
1 parent 6df7f40 commit 264927a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/spec/controllers/changeset_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ module CSControllerTest
controller.stub!(:notice)
controller.stub!(:errors)

@org = new_test_org #controller.current_organization
controller.stub!(:current_organization).and_return(@org)
@org = new_test_org

CSControllerTest::ENVIRONMENT["organization"] = @org
@env = KPEnvironment.create(CSControllerTest::ENVIRONMENT)
Expand Down
24 changes: 21 additions & 3 deletions src/spec/controllers/systems_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,35 @@
describe SystemsController do
include LoginHelperMethods
include LocaleHelperMethods
include SystemHelperMethods

before (:each) do
login_user
set_default_locale
setup_system_creation
end

describe "viewing systems" do
before (:each) do
150.times{|a| System.create!(:name=>"bar#{a}", :cp_type=>"system", :facts=>{"Test" => ""})}
end

it "should show the system 2 pane list" do
get :index
response.should be_success
response.should render_template("index")
assigns[:systems].should include System.find(8)
assigns[:systems].should_not include System.find(30)
end

describe "GET 'index'" do
it "should be successful" do
get 'index'
it "should return a portion of systems" do
get :items, :offset=>25
response.should be_success
response.should render_template("list_items")
assigns[:systems].should include System.find(30)
assigns[:systems].should_not include System.find(8)
end

end

end
2 changes: 2 additions & 0 deletions src/spec/helpers/organization_helper_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def new_test_org user=nil
Candlepin::Owner.stub!(:create_user).and_return(true)
Candlepin::Owner.should_receive(:create).at_least(:once).and_return({})
@organization = Organization.create!(:name => 'test_organization', :cp_key => 'test_organization')
session[:current_organization_id] = @organization.id
return @organization
end

end
9 changes: 9 additions & 0 deletions src/spec/helpers/system_helper_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include OrganizationHelperMethods

module SystemHelperMethods
def setup_system_creation
new_test_org
Candlepin::Consumer.should_receive(:create).at_least(:once).and_return({:owner=> { :key=> 'test_organization'}})
end

end
1 change: 1 addition & 0 deletions src/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'helpers/login_helper_methods'
require 'helpers/locale_helper_methods'
require 'helpers/organization_helper_methods'
require 'helpers/system_helper_methods'
require 'helpers/product_test_data.rb'
require 'helpers/product_helper_methods'
require 'models/model_spec_helper'
Expand Down

0 comments on commit 264927a

Please sign in to comment.