Changeset 589

Show
Ignore:
Timestamp:
03/22/07 12:30:23 (2 years ago)
Author:
jarmo
Message:
  • Fixed some broken tests on baseline
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/baseline/app/views/form/_creation_form.rhtml

    r587 r589  
    3737      <td><%= check_box(:form, :editable) %></td> 
    3838    </tr> 
    39     <% if @selected_asset.authorized_to(:create_task) and not @task_types.empty? %> 
     39    <% if @selected_asset.authorized_to(:create_task) and @task_types and not @task_types.empty? %> 
    4040      <tr> 
    4141        <th><%= _('Create new a task associated to this form') %></th> 
  • branches/baseline/db/migrate/001_baseline.rb

    r587 r589  
    319319    create_table 'type_attachments', :force => true do |t| 
    320320      t.column 'asset_type_id', :integer, :references => :asset_types, :null => false, :on_delete => :restrict, :on_update => :restrict 
    321       t.column 'name', :string, :limit => 40, :null => false 
     321      t.column 'name', :string, :limit => 40 
    322322      t.column 'filename', :string, :limit => 100, :null => false 
    323323      t.column 'content_type', :string, :limit => 100, :null => false 
  • branches/baseline/test/functional/task_type_controller_test.rb

    r585 r589  
    7171    login('test')   
    7272 
    73     post 'create', :name => 'Valid name' 
    74     assert_response :success 
    75     assert_template 'shared/_create_or_edit' 
     73    post 'create', :model => { :name => 'Valid name' } 
     74    assert_response :redirect 
     75    assert_redirected_to :action => 'list' 
    7676    assert_equal true, assigns(:model).errors.empty? 
    7777    assert_equal false, assigns(:model).new_record? 
  • branches/baseline/test/test_helper.rb

    r588 r589  
    145145 
    146146  # Creates a new task to asset+ 
    147   def create_task(task_type, asset, ready = false, short_description = 'Short description') 
     147  def create_task(asset, ready = false, short_description = 'Short description') 
     148    type = TaskType.find_by_name('Valid name') 
     149    type ||= TaskType.create!(:name => 'Valid name') 
    148150    w = Task.new(:short_description => short_description) 
    149     w.task_type = task_type 
     151    w.task_type = type 
    150152    w.asset = asset 
    151153    w.ready = ready 
     
    157159  def create_raw_task(asset, ready = false, short_description = 'Short description') 
    158160    tt = TaskType.find_by_name('create_raw_task') 
    159     tt ||= TaskType.create(:name => 'create_raw_task') 
     161    tt ||= TaskType.create!(:name => 'create_raw_task') 
    160162 
    161163    tmp = TempTask.create!(:asset_id => asset.id, :ready => ready, :short_description => short_description, :task_type_id => tt.id) 
     
    164166 
    165167  # Creates a new form to asset+ 
    166   def create_form(form_type, asset, ready = false, other_read = false, other_edit = false) 
     168  def create_form(asset, ready = false, other_read = false, other_edit = false) 
     169    type = FormType.find_by_name('Valid name') 
     170    type ||= FormType.create!(:name => 'Valid name', :ready => true, :editable => true) 
    167171    r = Form.new(:other_read => other_read, :other_edit => other_edit) 
    168     r.form_type = form_type 
     172    r.form_type = type 
    169173    r.asset = asset 
    170174    r.ready = ready 
     
    176180  def create_raw_form(asset, ready = false, other_read = false, other_edit = false) 
    177181    ft = FormType.find_by_name('create_raw_form') 
    178     ft ||= FormType.create(:name => 'create_raw_form', :editable => false, :ready => true) 
     182    ft ||= FormType.create!(:name => 'create_raw_form', :editable => false, :ready => true) 
    179183 
    180184    tmp = TempForm.create!(:asset_id => asset.id, :ready => ready, :other_read => other_read, :other_edit => other_edit, :form_type_id => ft.id) 
  • branches/baseline/test/unit/asset_type_test.rb

    r576 r589  
    1515    # Create an asset type 
    1616    @icon = AssetTypeIcon.create!(:file => uploaded_file('assets.png', 'image/png', 'test_icon.png')) 
    17     @asset_type = AssetType.create!(:name => 'Test', :asset_type_icon_id => @icon.id, :set_typical_maintenance_time_interval => {:months => 1}
    18     @unauthorized_asset_type = AssetType.create!(:name => 'Unauthorized', :asset_type_icon_id => @icon.id, :set_typical_maintenance_time_interval => {:months => 1}
     17    @asset_type = AssetType.create!(:name => 'Test', :asset_type_icon_id => @icon.id
     18    @unauthorized_asset_type = AssetType.create!(:name => 'Unauthorized', :asset_type_icon_id => @icon.id
    1919 
    2020    # Create two assets to the asset type, which the user is authorized to read and to create some data to them. 
     
    6262  end 
    6363 
    64   def test_set_and_get_typical_maintenance_time_interval 
    65     time = {:years => 1, :months => 2, :days => 3, :hours => 4, :minutes => 5} 
    66     time_str = {'years' => '1', 'months' => '2', 'days' => '3', 'hours' => '4', 'minutes' => '5'} 
    67     time_in_seconds = AssetType::YEAR + 2*AssetType::MONTH + 3*AssetType::DAY + 4*AssetType::HOUR + 5*AssetType::MINUTE 
    68  
    69     @asset_type.set_typical_maintenance_time_interval = time 
    70     assert_equal time_in_seconds, @asset_type.typical_maintenance_time_interval 
    71     @asset_type.set_typical_maintenance_time_interval = time_str 
    72     assert_equal time_in_seconds, @asset_type.typical_maintenance_time_interval 
    73     assert_equal time, @asset_type.get_typical_maintenance_time_interval 
    74   end 
    75  
    76   def test_typical_maintenance_time_intervals_positivity 
    77     icon = AssetTypeIcon.create!(:file => uploaded_file('assets.png', 'image/png', 'test_icon.png')) 
    78     asset_type = AssetType.new(:name => 'Unigue', :asset_type_icon_id => icon.id) 
    79     asset_type.typical_maintenance_time_interval = 0 
    80     assert_equal false, asset_type.valid? 
    81     asset_type.typical_maintenance_time_interval = 1 
    82     assert_equal true, asset_type.valid? 
    83   end 
    84  
    8564  # Function: test_destroy_associated_data 
    8665  # ====================================== 
  • branches/baseline/test/unit/protected_data_test.rb

    r581 r589  
    3030    # Create a task to which the @user_group has all permissions and 
    3131    # @another_user_group has read and change state permissions to the task. 
     32    @task_type = TaskType.create!(:name => 'Valid name') 
    3233    @task_authorized_to_edit = create_task(@root_asset, true, 'Test task') 
    3334    @wop1 = @task_authorized_to_edit.data_permissions.create!(:user_group_id => @user_group.id, :group_read => true, :group_change_state => true, :group_edit => true) 
     
    488489  def test_before_create_form_without_user 
    489490    User.current_user = nil 
     491    ft = FormType.create!(:name => 'Valid name', :ready => true, :editable => true) 
    490492    r = Form.new 
     493    r.form_type = ft 
    491494    r.asset = @root_asset 
    492495    assert_equal true, r.valid? 
     
    499502 
    500503    # New object can only be saved if creator has creation permission to object's asset. 
     504    ft = FormType.create!(:name => 'Valid name', :ready => true, :editable => true) 
    501505    r = Form.new 
     506    r.form_type = ft 
    502507    r.asset = asset 
    503508    assert_equal true, r.valid? 
     
    519524    # New object can only be saved if creator has creation permission to object's asset. 
    520525    w = Task.new(:short_description => 'Short description') 
     526    w.task_type = @task_type 
    521527    w.asset = asset 
    522528    assert_equal true, w.valid? 
     
    712718  def test_before_update_stateless_data 
    713719    setup_extra_forms 
    714     type = FormType.create!(:name => 'Test type'
     720    type = FormType.create!(:name => 'Test type', :ready => true, :editable => true
    715721 
    716722    # User doesn't have permission to change state or/and edit these objects, so saving should fail. 
  • branches/baseline/test/unit/task_test.rb

    r539 r589  
    1515 
    1616    # Create test task 
     17    @task_type = TaskType.create(:name => 'Valid name') 
    1718    @valid_task = Task.new 
     19    @valid_task.task_type = @task_type 
    1820    @valid_task.asset = @root_asset 
    1921    @valid_task.short_description = 'asdf' 
     
    239241  end 
    240242 
    241   def test_calculate_resource_usage 
    242     Task.delete_all 
    243     assert_equal 0, Task.count   
    244  
    245     # Create test tasks 
    246     wo1 = Task.new(:short_description => 'test1', :starting_time => 1.hours.from_now, :deadline => 3.hours.from_now, :estimated_working_time => 1) 
    247     wo1.asset = @root_asset 
    248     wo1.ready = true 
    249     wo1.save 
    250  
    251     wo2 = Task.new(:short_description => 'test2', :starting_time => 2.hours.from_now, :deadline => 5.hours.from_now, :estimated_working_time => 10) 
    252     wo2.asset = @root_asset 
    253     wo2.ready = true 
    254     wo2.save 
    255  
    256     wo3 = Task.new(:short_description => 'test3', :starting_time => nil, :deadline => 3.hours.from_now, :estimated_working_time => 100) 
    257     wo3.asset = @root_asset 
    258     wo3.ready = true 
    259     wo3.save 
    260  
    261     wo4 = Task.new(:short_description => 'test4', :starting_time => 2.hours.from_now, :deadline => nil, :estimated_working_time => 1000) 
    262     wo4.asset = @root_asset 
    263     wo4.ready = true 
    264     wo4.save 
    265  
    266     assert_equal 4, Task.count   
    267  
    268     assert_equal [100.0, 101.0, 1111.0, 1010.0, 1010.0, 1000.0], Task.calculate_resource_usage(['asset_id = ?', @root_asset.id], 5.hours, 1.hours) 
    269    
    270   end 
    271  
    272243end 

© 2004-2007 Norfello Oy All Rights Reserved