diff --git a/app/models/exercise.rb b/app/models/exercise.rb index c31f17dde..647f43151 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -13,7 +13,7 @@ class Exercise < ActiveRecord::Base belongs_to :user belongs_to :execution_environment has_many :descriptions - validates :descriptions, presence: true + #validates :descriptions, presence: true accepts_nested_attributes_for :descriptions, allow_destroy: true diff --git a/app/views/home/_exercises.html.erb b/app/views/home/_exercises.html.erb index ca98f9c64..fade35f24 100644 --- a/app/views/home/_exercises.html.erb +++ b/app/views/home/_exercises.html.erb @@ -24,7 +24,7 @@
- <%= exercise.descriptions.first.text %> + <% unless exercise.descriptions.empty? %><%= exercise.descriptions.first.text %><% end %>
diff --git a/db/seeds.rb b/db/seeds.rb index 491d95bb4..d82cb9644 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -25,7 +25,7 @@ test_framework = TestingFramework.create(name: 'JUnit 4') test_framework2 = TestingFramework.create(name: 'Pytest') -exercise1 = Exercise.create(title: "Hello World", description: "Schreibe ein Java Programm, das 'Hello World' am Bildschirm ausgibt.", maxrating: '10', public: true, user_id:user1.id) +exercise1 = Exercise.create(title: "Hello World", maxrating: '10', public: true, user_id:user1.id) ExerciseFile.create(main: true, content: "public class HelloWorld{ public static void main String[] args) { } }", path: '', solution: false, filetype: 'java', exercise: exercise1) Test.create(content: "public class HelloWorld{ public static void main String[] args) {System.out.println('Hello World.'); } }", rating: 5, feedback_message: "Es wird noch nicht 'Hello World' am Bildschrim ausgegeben!", exercise: exercise1, testing_framework: test_framework) @@ -52,7 +52,7 @@ -exercise2 = Exercise.create(title: "Java Einstieg ", description: "In diesem Programm sind zwei Fehler versteckt. Versuche diese zu finden und zu beheben. Anschließend soll das Programm ""Hallo Welt"" ausgeben.\nFinde die beiden Fehler, die wir in das Programm eingebaut haben.", maxrating: '10', public: true, user_id:user2.id) +exercise2 = Exercise.create(title: "Java Einstieg ", maxrating: '10', public: true, user_id:user2.id) ExerciseFile.create(main: true, content: "public class HalloWelt {\n // Hier haben sich zwei Fehler eingeschlichen\n public static void main (String [] args){\n System.out.println(Hallo Welt)\n }\n}", path: '', solution: false, filetype: 'java', exercise: exercise2) Test.create(content: "import static org.junit.Assert.*;\nimport java.io.ByteArrayOutputStream;\nimport java.io.PrintStream;\nimport org.junit.AfterClass;\nimport org.junit.Before;\nimport org.junit.BeforeClass;\nimport org.junit.Test;\npublic class HalloWeltTest1 {\n \n private final static ByteArrayOutputStream outContent = new ByteArrayOutputStream();\n private static PrintStream old;\n @BeforeClass\n public static void setUpStreams() {\n old = System.out;\n System.setOut(new PrintStream(outContent));\n }\n @AfterClass\n public static void cleanUpStreams() {\n System.setOut(old);\n }\n \n @Before\n public void resetOut(){\n outContent.reset();\n }\n \n @Test\n public void testIfErrorFree(){\n try{\n HalloWelt.main(new String[] {});\n }catch (Error e){\n fail();\n }\n }\n @Test\n public void testSomething(){\n assert(true);\n }\n}", rating: 5, feedback_message: "Es existieren noch Fehler im Programm. Daher kann dieses noch nicht ausgeführt werden", exercise: exercise2, testing_framework: test_framework) Test.create(content: "import static org.junit.Assert.*;\nimport java.io.ByteArrayOutputStream;\nimport java.io.PrintStream;\nimport org.junit.AfterClass;\nimport org.junit.Before;\nimport org.junit.BeforeClass;\nimport org.junit.Test;\npublic class HalloWeltTest2 {\n \n private final static ByteArrayOutputStream outContent = new ByteArrayOutputStream();\n private static PrintStream old;\n @BeforeClass\n public static void setUpStreams() {\n old = System.out;\n System.setOut(new PrintStream(outContent));\n }\n @AfterClass\n public static void cleanUpStreams() {\n System.setOut(old);\n }\n \n @Before\n public void resetOut(){\n outContent.reset();\n }\n \n @Test\n public void checkForCorrectOutput(){\n HalloWelt.main(new String[] {});\n String separator = System.getProperty(""line.separator"");\n assertEquals(""Hallo Welt""+separator, outContent.toString());\n }\n @Test\n public void testSomething(){\n assert(true);\n }\n}", rating: 1, feedback_message: "Es wird ein falscher String ausgegeben, erwartet ist die Ausgabe\nHallo Welt", exercise: exercise2, testing_framework: test_framework) @@ -71,7 +71,7 @@ exercise2.labels << l3 -exercise3 = Exercise.create(title: "Asterisk Pattern", description: "Schreibe ein Java Programm, das das Asterisk Pattern ausgibt. Das Pattern sieht folgendermaßen aus: ***** ***** ***** ***** *****", maxrating: '10', public: true, user_id:user3.id) +exercise3 = Exercise.create(title: "Asterisk Pattern", maxrating: '10', public: true, user_id:user3.id) ExerciseFile.create(main: true, content: "public class AsteriksPattern{ public static void main String[] args) { } }", path: '', solution: false, filetype: 'java', exercise: exercise3) @@ -104,7 +104,7 @@ exercise3.labels << l3 -exercise4 = Exercise.create(title: "factorial of given numbers", description: "Write a program which can compute the factorial of a given numbers. The results should be printed in a comma-separated sequence on a single line.", maxrating: '10', public: true, user_id:user4.id) +exercise4 = Exercise.create(title: "factorial of given numbers", maxrating: '10', public: true, user_id:user4.id) ExerciseFile.create(main: true, content: "def fact(x): return", path: '', solution: false, filetype: 'python', exercise: exercise4)