Changeset 88
- Timestamp:
- 04/16/08 22:25:45 (7 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
CHANGELOG.txt (modified) (1 diff)
-
app/models/recipe.rb (modified) (1 diff)
-
test/unit/recipe_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG.txt
r87 r88 1 1 2 2 * SVN * 3 4 * Check syntax of recipes. Provided by Mathias Meyer 3 5 4 6 * Ajax-Preview on recipe edit. Provided by Mathias Meyer -
trunk/app/models/recipe.rb
r51 r88 9 9 10 10 tz_time_attributes :created_at, :updated_at 11 12 13 def validate 14 check_syntax 15 end 16 17 def check_syntax 18 return if self.body.blank? 19 20 result = "" 21 Open4::popen4 "ruby -wc" do |pid, stdin, stdout, stderr| 22 stdin.write self.body 23 stdin.close 24 output = stdout.read 25 errors = stderr.read 26 result = output.any? ? output : errors 27 end 28 29 unless result == "Syntax OK" 30 line = $1.to_i if result =~ /^-:(\d+):/ 31 errors.add(:body, "syntax error at line: #{line}") unless line.nil? 32 end 33 rescue => e 34 RAILS_DEFAULT_LOGGER.error "Error while validating recipe syntax of recipe #{self.id}: #{e.inspect} - #{e.backtrace.join("\n")}" 35 end 36 11 37 end -
trunk/test/unit/recipe_test.rb
r1 r88 51 51 assert !recipe.valid? 52 52 end 53 54 def test_validate_invalid_syntax_on_create 55 recipe = Recipe.create(:name => "Copy Config files", 56 :description => "Recipe body intentionally erronous", 57 :body => "set config_files, database.yml'") 58 assert !recipe.valid? 59 assert_equal "syntax error at line: 1", recipe.errors.on(:body) 60 end 53 61 62 def test_validate_valid_syntax_on_create 63 recipe = Recipe.create(:name => "Copy Config files", 64 :description => "Recipe body intentionally erronous", 65 :body => "set :config_files, 'database.yml'") 66 assert !recipe.errors.on(:body) 67 end 68 69 def test_validate_with_open4_error 70 Open4.expects(:popen4).raises(RuntimeError) 71 recipe = Recipe.create(:name => "Copy Config files", 72 :description => "Recipe body intentionally erronous", 73 :body => "set :config_files, 'database.yml'") 74 assert !recipe.errors.on(:body) 75 end 54 76 end
