<commit_before>require File.dirname(__FILE__) + '/../test_helper'
require 'networks_controller'

# Re-raise errors caught by the controller.
class NetworksController; def rescue_action(e) raise e end; end

class NetworksControllerTest < Test::Unit::TestCase
  fixtures :pages, :users, :groups, :user_participations, :group_participations, :discussions, :memberships, :posts, :activities
  def setup
    @controller = NetworksController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

=begin
  def test_index
    login_as :blue
    get :index
    assert_response :redirect
    assert_redirected_to :action => :list
  end

  def test_list
    login_as :blue
    get :list
    assert_response :success
  end
=end
  def test_create
    login_as :blue
    get :new
    assert_response :success, "should be able to create new network"
    assert_select "form#createform[method=post][action=?]", networks_url(:action=>:create, :only_path => true)

    assert_difference 'groups(:animals).networks.count',1,"animals group should be part of network" do
      create_network_for_animals
    end
  end

  def create_with_no_groups
    login_as :blue
    post :create, :group => {:name => 'baby-bat'}
    network = Network.find(:last)
    assert 'baby-bat', network.name
    assert network.users.any?
    assert 'blue', network.users.first.name
  end

  def test_failed_create
    login_as :red
    get :new
    assert_response :success
    assert_no_difference 'groups(:animals).networks.count',"should not be allowed to add animals group to new network" do
      create_network_for_animals
    end
  end

  protected

  def create_network_for_animals
    assert_difference 'Network.count', 1, "new network should be created" do
      post :create,
        :group => {:name => 'testnet'},
        :group_id => groups(:animals).id
      assert_response :redirect, "redirect to edit on creation of new network"
      assert_redirected_to :controller => :networks, :action=>'edit', :id=>'testnet'
    end
  end
end

<commit_msg>fixed networks test<commit_after>require File.dirname(__FILE__) + '/../test_helper'
require 'networks_controller'

# Re-raise errors caught by the controller.
class NetworksController; def rescue_action(e) raise e end; end

class NetworksControllerTest < Test::Unit::TestCase
  fixtures :users, :groups, :memberships, :federatings

  def setup
    @controller = NetworksController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_show
    login_as :blue
    get :show, :id => groups(:fai).to_param
    assert_response :success
  end

  def test_create
    login_as :blue
    get :new
    assert_response :success, "should be able to create new network"
    assert_select "form#createform[method=post][action=?]", networks_url(:action=>:create, :only_path => true)

    assert_difference 'groups(:animals).networks.count',1,"animals group should be part of network" do
      create_network(:name => 'testnet', :group => :animals)
      assert_response :redirect, "redirect to edit on creation of new network"
      assert_redirected_to :controller => :networks, :action=>'edit', :id=>'testnet'
    end
  end

  def create_with_no_groups
    login_as :blue
    post :create, :group => {:name => 'baby-bat'}
    network = Network.find(:last)
    assert 'baby-bat', network.name
    assert network.users.any?
    assert 'blue', network.users.first.name
  end

  def test_failed_create
    login_as :red
    get :new
    assert_response :success
    assert_no_difference 'groups(:animals).networks.count',"should not be allowed to add animals group to new network" do
      create_network(:name => 'testnetwork', :group => :animals)
    end
  end

  protected

  def create_network(opts)
    assert_difference 'Network.count', 1, "new network should be created" do
      post :create, :group => {:name => opts[:name]}, :group_id => groups(opts[:group]).id
    end
  end
end


{'fraction_non_alphanumeric': 0.10372208436724566, 'fraction_numerical': 0.0009925558312655087, 'mean_word_length': 3.9520884520884523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5385445', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1187, 'n_words': 345}