Changeset 589
- Timestamp:
- 03/22/07 12:30:23 (2 years ago)
- Files:
-
- branches/baseline/app/views/form/_creation_form.rhtml (modified) (1 diff)
- branches/baseline/db/migrate/001_baseline.rb (modified) (1 diff)
- branches/baseline/test/functional/task_type_controller_test.rb (modified) (1 diff)
- branches/baseline/test/test_helper.rb (modified) (4 diffs)
- branches/baseline/test/unit/asset_type_test.rb (modified) (2 diffs)
- branches/baseline/test/unit/protected_data_test.rb (modified) (5 diffs)
- branches/baseline/test/unit/task_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/baseline/app/views/form/_creation_form.rhtml
r587 r589 37 37 <td><%= check_box(:form, :editable) %></td> 38 38 </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? %> 40 40 <tr> 41 41 <th><%= _('Create new a task associated to this form') %></th> branches/baseline/db/migrate/001_baseline.rb
r587 r589 319 319 create_table 'type_attachments', :force => true do |t| 320 320 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 => false321 t.column 'name', :string, :limit => 40 322 322 t.column 'filename', :string, :limit => 100, :null => false 323 323 t.column 'content_type', :string, :limit => 100, :null => false branches/baseline/test/functional/task_type_controller_test.rb
r585 r589 71 71 login('test') 72 72 73 post 'create', : name => 'Valid name'74 assert_response : success75 assert_ template 'shared/_create_or_edit'73 post 'create', :model => { :name => 'Valid name' } 74 assert_response :redirect 75 assert_redirected_to :action => 'list' 76 76 assert_equal true, assigns(:model).errors.empty? 77 77 assert_equal false, assigns(:model).new_record? branches/baseline/test/test_helper.rb
r588 r589 145 145 146 146 # 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') 148 150 w = Task.new(:short_description => short_description) 149 w.task_type = t ask_type151 w.task_type = type 150 152 w.asset = asset 151 153 w.ready = ready … … 157 159 def create_raw_task(asset, ready = false, short_description = 'Short description') 158 160 tt = TaskType.find_by_name('create_raw_task') 159 tt ||= TaskType.create (:name => 'create_raw_task')161 tt ||= TaskType.create!(:name => 'create_raw_task') 160 162 161 163 tmp = TempTask.create!(:asset_id => asset.id, :ready => ready, :short_description => short_description, :task_type_id => tt.id) … … 164 166 165 167 # 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) 167 171 r = Form.new(:other_read => other_read, :other_edit => other_edit) 168 r.form_type = form_type172 r.form_type = type 169 173 r.asset = asset 170 174 r.ready = ready … … 176 180 def create_raw_form(asset, ready = false, other_read = false, other_edit = false) 177 181 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) 179 183 180 184 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 15 15 # Create an asset type 16 16 @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) 19 19 20 20 # Create two assets to the asset type, which the user is authorized to read and to create some data to them. … … 62 62 end 63 63 64 def test_set_and_get_typical_maintenance_time_interval65 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::MINUTE68 69 @asset_type.set_typical_maintenance_time_interval = time70 assert_equal time_in_seconds, @asset_type.typical_maintenance_time_interval71 @asset_type.set_typical_maintenance_time_interval = time_str72 assert_equal time_in_seconds, @asset_type.typical_maintenance_time_interval73 assert_equal time, @asset_type.get_typical_maintenance_time_interval74 end75 76 def test_typical_maintenance_time_intervals_positivity77 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 = 080 assert_equal false, asset_type.valid?81 asset_type.typical_maintenance_time_interval = 182 assert_equal true, asset_type.valid?83 end84 85 64 # Function: test_destroy_associated_data 86 65 # ====================================== branches/baseline/test/unit/protected_data_test.rb
r581 r589 30 30 # Create a task to which the @user_group has all permissions and 31 31 # @another_user_group has read and change state permissions to the task. 32 @task_type = TaskType.create!(:name => 'Valid name') 32 33 @task_authorized_to_edit = create_task(@root_asset, true, 'Test task') 33 34 @wop1 = @task_authorized_to_edit.data_permissions.create!(:user_group_id => @user_group.id, :group_read => true, :group_change_state => true, :group_edit => true) … … 488 489 def test_before_create_form_without_user 489 490 User.current_user = nil 491 ft = FormType.create!(:name => 'Valid name', :ready => true, :editable => true) 490 492 r = Form.new 493 r.form_type = ft 491 494 r.asset = @root_asset 492 495 assert_equal true, r.valid? … … 499 502 500 503 # 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) 501 505 r = Form.new 506 r.form_type = ft 502 507 r.asset = asset 503 508 assert_equal true, r.valid? … … 519 524 # New object can only be saved if creator has creation permission to object's asset. 520 525 w = Task.new(:short_description => 'Short description') 526 w.task_type = @task_type 521 527 w.asset = asset 522 528 assert_equal true, w.valid? … … 712 718 def test_before_update_stateless_data 713 719 setup_extra_forms 714 type = FormType.create!(:name => 'Test type' )720 type = FormType.create!(:name => 'Test type', :ready => true, :editable => true) 715 721 716 722 # 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 15 15 16 16 # Create test task 17 @task_type = TaskType.create(:name => 'Valid name') 17 18 @valid_task = Task.new 19 @valid_task.task_type = @task_type 18 20 @valid_task.asset = @root_asset 19 21 @valid_task.short_description = 'asdf' … … 239 241 end 240 242 241 def test_calculate_resource_usage242 Task.delete_all243 assert_equal 0, Task.count244 245 # Create test tasks246 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_asset248 wo1.ready = true249 wo1.save250 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_asset253 wo2.ready = true254 wo2.save255 256 wo3 = Task.new(:short_description => 'test3', :starting_time => nil, :deadline => 3.hours.from_now, :estimated_working_time => 100)257 wo3.asset = @root_asset258 wo3.ready = true259 wo3.save260 261 wo4 = Task.new(:short_description => 'test4', :starting_time => 2.hours.from_now, :deadline => nil, :estimated_working_time => 1000)262 wo4.asset = @root_asset263 wo4.ready = true264 wo4.save265 266 assert_equal 4, Task.count267 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 end271 272 243 end