gnarus_exercise 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -3,21 +3,21 @@ GnarusExercise
3
3
 
4
4
  This project rocks and uses MIT-LICENSE.
5
5
 
6
- Configuring a new project without user ownership
7
- ================================================
6
+ Configuring a new project
7
+ =========================
8
8
 
9
9
  ```
10
10
  rails new my_exercise -m https://raw.github.com/caelum/gnarus-exercise/master/template.rb
11
11
  ```
12
12
 
13
- You will be prompted about add <code>devise</code> into your application, then is up
14
- to you accept or not. The template will handle all the configurations for you.
13
+ You will be prompted about adding <code>devise</code> into your application, then it is up
14
+ to you accept or not (if you want to auth your exercises). The template will handle all configuration required for you.
15
15
 
16
16
 
17
17
  TODO
18
18
  ====
19
19
 
20
20
  - update method UPDATE from exercise to be safe
21
- - exercisecontroller entire code should work with/without devise
22
- - no need to override gnarusexercises:exercise would be lovely
23
- - eval solution?
21
+ - rename to gnarus-exercise
22
+ - we are using the index file to show an attempt, nasty. a GET to a better named method
23
+ - automatic reload from ActivityProcessor
@@ -0,0 +1,27 @@
1
+ var gnarus = {
2
+ attemptForm : function(solution, viewer, returnUri) {
3
+
4
+ var viewChanged = function(execution) {
5
+ viewer(execution);
6
+ if(execution.suceeded) {
7
+ var form = $('<form action=' + returnUri + '></form>');
8
+ var input = $('<input name="solution" />');
9
+ input.val(execution.solution);
10
+ form.insertAfter(input);
11
+ form.submit();
12
+ }
13
+ };
14
+
15
+ return {
16
+ process : function() {
17
+ var target = $('#exercise').attr('action');
18
+ $.post(target, solution(), function(r) {
19
+ viewChanged(r);
20
+ });
21
+ },
22
+ setup : function() {
23
+ $('#try').click(this.process);
24
+ }
25
+ };
26
+ }
27
+ };
@@ -1,21 +1,13 @@
1
1
  module GnarusExercise
2
- class AttemptsController < ApplicationController
2
+ class AttemptsController < ApplicationController
3
3
 
4
- skip_before_filter :verify_authenticity_token
4
+ skip_before_filter :verify_authenticity_token
5
5
 
6
- def update
7
- @attempt = Attempt.find(params[:id])
8
- if(@attempt.not_finished)
9
- @attempt.update_attributes(:solution => params[:path])
6
+ def index
7
+ exercise = Exercise.find(params[:exercise_id])
8
+ @attempt = exercise.attempts.create(params[:attempt])
9
+ @attempt.save
10
10
  end
11
- redirect_to @attempt.full_return_uri
12
- end
13
11
 
14
- def index
15
- exercise = Exercise.find(params[:exercise_id])
16
- @attempt = exercise.attempts.create(params[:attempt])
17
- @attempt.save
18
12
  end
19
-
20
- end
21
13
  end
@@ -0,0 +1,14 @@
1
+ module GnarusExercise
2
+ class ExecutionsController < ApplicationController
3
+
4
+ skip_before_filter :verify_authenticity_token
5
+
6
+ def create
7
+ @attempt = Attempt.find params[:attempt_id]
8
+ execution = ::ActivityProcessor.process @attempt, params
9
+ execution.save
10
+ render :json => execution.to_json(:includes => :attempt)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class ActivityProcessor
2
+ def self.process(attempt, params)
3
+ attempt.executions.create :solution => params[:solution], :suceeded => true
4
+ end
5
+ end
@@ -1,13 +1,16 @@
1
1
  module GnarusExercise
2
2
  class Attempt < ActiveRecord::Base
3
3
  belongs_to :exercise
4
- attr_accessible :return_uri, :solution
4
+ has_many :executions
5
+ attr_accessible :return_uri, :author_id
5
6
 
6
- def not_finished
7
- solution.nil?
8
- end
9
7
  def full_return_uri
10
8
  (return_uri || "") + "?answer=" + (solution || "")
11
9
  end
10
+
11
+ def process(params)
12
+ executions.create :solution => params[:solution], :suceeded => params[:suceeded]
13
+ end
14
+
12
15
  end
13
16
  end
@@ -0,0 +1,6 @@
1
+ module GnarusExercise
2
+ class Execution < ActiveRecord::Base
3
+ attr_accessible :attempt, :solution, :suceeded
4
+ belongs_to :attempt
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ require 'activity_processor'
data/config/routes.rb CHANGED
@@ -3,7 +3,9 @@ GnarusExercise::Engine.routes.draw do
3
3
  root :to => "exercises#index"
4
4
 
5
5
  resources :exercises do
6
- resources :attempts
6
+ resources :attempts do
7
+ resources :executions
8
+ end
7
9
  end
8
10
 
9
11
  end
@@ -3,7 +3,7 @@ class CreateGnarusExerciseAttempts < ActiveRecord::Migration
3
3
  create_table :gnarus_exercise_attempts do |t|
4
4
  t.references :exercise
5
5
  t.text :return_uri
6
- t.text :solution
6
+ t.string :author_id
7
7
 
8
8
  t.timestamps
9
9
  end
@@ -0,0 +1,12 @@
1
+ class CreateGnarusExerciseExecutions < ActiveRecord::Migration
2
+ def change
3
+ create_table :gnarus_exercise_executions do |t|
4
+ t.references :attempt
5
+ t.text :solution
6
+ t.boolean :suceeded
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :gnarus_exercise_executions, :attempt_id
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module GnarusExercise
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ attempt:
5
+ solution: MyString
6
+ suceeded: false
7
+
8
+ two:
9
+ attempt:
10
+ solution: MyString
11
+ suceeded: false
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module GnarusExercise
4
+ class ExecutionTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
metadata CHANGED
@@ -1,80 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gnarus_exercise
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 1
10
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Guilherme Silveira
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-06 00:00:00 -03:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 3
32
- - 2
33
- - 2
20
+ - !ruby/object:Gem::Version
34
21
  version: 3.2.2
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: sqlite3
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
41
25
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
49
38
  type: :development
50
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
51
46
  description: Create external exercises by mounting this plugin.
52
- email:
47
+ email:
53
48
  - guilherme.silveira@caelum.com.br
54
49
  executables: []
55
-
56
50
  extensions: []
57
-
58
51
  extra_rdoc_files: []
59
-
60
- files:
52
+ files:
61
53
  - app/assets/javascripts/gnarus_exercise/application.js
54
+ - app/assets/javascripts/gnarus_exercise/attempt.js
62
55
  - app/assets/stylesheets/gnarus_exercise/application.css
63
56
  - app/controllers/gnarus_exercise/application_controller.rb
64
57
  - app/controllers/gnarus_exercise/attempts_controller.rb
58
+ - app/controllers/gnarus_exercise/executions_controller.rb
65
59
  - app/controllers/gnarus_exercise/exercises_controller.rb
66
60
  - app/helpers/gnarus_exercise/application_helper.rb
61
+ - app/models/activity_processor.rb
67
62
  - app/models/gnarus_exercise/attempt.rb
63
+ - app/models/gnarus_exercise/execution.rb
68
64
  - app/models/gnarus_exercise/exercise.rb
69
65
  - app/views/gnarus_exercise/exercises/_form.html.erb
66
+ - app/views/gnarus_exercise/exercises/_my_fields.html.erb
70
67
  - app/views/gnarus_exercise/exercises/edit.html.erb
71
68
  - app/views/gnarus_exercise/exercises/index.html.erb
72
69
  - app/views/gnarus_exercise/exercises/new.html.erb
73
70
  - app/views/gnarus_exercise/exercises/show.html.erb
74
71
  - app/views/layouts/gnarus_exercise/application.html.erb
72
+ - config/initializers/gnarus_exercise.rb
75
73
  - config/routes.rb
76
74
  - db/migrate/20120405185453_create_gnarus_exercise_exercises.rb
77
75
  - db/migrate/20120405185533_create_gnarus_exercise_attempts.rb
76
+ - db/migrate/20120408064126_create_gnarus_exercise_executions.rb
78
77
  - lib/gnarus_exercise/engine.rb
79
78
  - lib/gnarus_exercise/version.rb
80
79
  - lib/gnarus_exercise.rb
@@ -111,49 +110,41 @@ files:
111
110
  - test/dummy/README.rdoc
112
111
  - test/dummy/script/rails
113
112
  - test/fixtures/gnarus_exercise/attempts.yml
113
+ - test/fixtures/gnarus_exercise/executions.yml
114
114
  - test/fixtures/gnarus_exercise/exercises.yml
115
115
  - test/fixtures/gnarus_exercise/users.yml
116
116
  - test/gnarus_exercise_test.rb
117
117
  - test/integration/navigation_test.rb
118
118
  - test/test_helper.rb
119
119
  - test/unit/gnarus_exercise/attempt_test.rb
120
+ - test/unit/gnarus_exercise/execution_test.rb
120
121
  - test/unit/gnarus_exercise/exercise_test.rb
121
122
  - test/unit/gnarus_exercise/user_test.rb
122
- has_rdoc: true
123
123
  homepage: http://online.caelum.com.br
124
124
  licenses: []
125
-
126
125
  post_install_message:
127
126
  rdoc_options: []
128
-
129
- require_paths:
127
+ require_paths:
130
128
  - lib
131
- required_ruby_version: !ruby/object:Gem::Requirement
129
+ required_ruby_version: !ruby/object:Gem::Requirement
132
130
  none: false
133
- requirements:
134
- - - ">="
135
- - !ruby/object:Gem::Version
136
- hash: 3
137
- segments:
138
- - 0
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
136
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
- version: "0"
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
149
141
  requirements: []
150
-
151
142
  rubyforge_project:
152
- rubygems_version: 1.3.7
143
+ rubygems_version: 1.8.19
153
144
  signing_key:
154
145
  specification_version: 3
155
146
  summary: A plugin structure for external exercises.
156
- test_files:
147
+ test_files:
157
148
  - test/dummy/app/assets/javascripts/application.js
158
149
  - test/dummy/app/assets/stylesheets/application.css
159
150
  - test/dummy/app/controllers/application_controller.rb
@@ -183,11 +174,13 @@ test_files:
183
174
  - test/dummy/README.rdoc
184
175
  - test/dummy/script/rails
185
176
  - test/fixtures/gnarus_exercise/attempts.yml
177
+ - test/fixtures/gnarus_exercise/executions.yml
186
178
  - test/fixtures/gnarus_exercise/exercises.yml
187
179
  - test/fixtures/gnarus_exercise/users.yml
188
180
  - test/gnarus_exercise_test.rb
189
181
  - test/integration/navigation_test.rb
190
182
  - test/test_helper.rb
191
183
  - test/unit/gnarus_exercise/attempt_test.rb
184
+ - test/unit/gnarus_exercise/execution_test.rb
192
185
  - test/unit/gnarus_exercise/exercise_test.rb
193
186
  - test/unit/gnarus_exercise/user_test.rb