Commit 998035d2e57181f68672ed40998beb5bc4b8c5f7

Authored by Diego Martinez
2 parents 0447e562 fbcae806

Merge branch 'refactoring_repository' of gitorious.org:+mezuro/noosfero/mezuro i…

…nto refactoring_repository
plugins/mezuro/lib/kalibro/configuration.rb
@@ -9,7 +9,7 @@ class Kalibro::Configuration < Kalibro::Model @@ -9,7 +9,7 @@ class Kalibro::Configuration < Kalibro::Model
9 def self.all 9 def self.all
10 response = request(:all_configurations)[:configuration] 10 response = request(:all_configurations)[:configuration]
11 response = [] if response.nil? 11 response = [] if response.nil?
12 - response = [response] if response.is_a? (Hash) 12 + response = [response] if response.is_a?(Hash)
13 response.map {|configuration| new configuration} 13 response.map {|configuration| new configuration}
14 end 14 end
15 15
plugins/mezuro/test/functional/profile/mezuro_plugin_repository_controller_test.rb
@@ -15,18 +15,35 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase @@ -15,18 +15,35 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase
15 @profile = fast_create(Community) 15 @profile = fast_create(Community)
16 16
17 @repository = RepositoryFixtures.repository 17 @repository = RepositoryFixtures.repository
  18 + @repository_hash = RepositoryFixtures.hash
18 @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => name) 19 @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => name)
19 @content.expects(:send_project_to_service).returns(nil) 20 @content.expects(:send_project_to_service).returns(nil)
20 @content.stubs(:solr_save) 21 @content.stubs(:solr_save)
21 @content.save 22 @content.save
22 end 23 end
23 24
24 - should 'test stuff' do  
25 - Kalibro::Repository.expects(:repository_types).returns(RepositoryFixtures.types)  
26 - #Kalibro::Configuration.any_instance.expects(:all).returns(ConfigurationFixtures.all) 25 + should 'provide the correct variables to the "new" view' do
  26 + repository_types = RepositoryFixtures.types
  27 + all_configurations = ConfigurationFixtures.all
  28 + Kalibro::Repository.expects(:repository_types).returns(repository_types)
  29 + Kalibro::Configuration.expects(:all).returns(all_configurations)
27 30
28 - get :new_repository, :profile => @profile.identifier, :id => @content.id 31 + get :new, :profile => @profile.identifier, :id => @content.id
29 32
30 - #assert_equal RepositoryFixtures.types, assigns(:repository_types) 33 + #assert_equal @content, assigns(:project_content)
  34 + assert_equal repository_types, assigns(:repository_types)
  35 + assert_equal all_configurations.first.name, assigns(:configuration_select).first.first
  36 + assert_equal all_configurations.first.id, assigns(:configuration_select).first.last
31 end 37 end
32 -end  
33 \ No newline at end of file 38 \ No newline at end of file
  39 +
  40 + should 'create a repository and redirect correctly' do
  41 + Kalibro::Repository.expects(:new).returns(@repository)
  42 + @repository.expects(:save).with(@content.project_id).returns(true)
  43 + get :create, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash
  44 + assert @repository.errors.empty?
  45 + assert_response :redirect
  46 + assert_select('h5', 'Repositories')
  47 + end
  48 +
  49 +
  50 +end