Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Results storage

  • Loading branch information...
commit db3855361411b8d9d5f472089d17a2c7705bc803 1 parent e029450
@eoftedal authored
View
10 app/controllers/application_controller.rb
@@ -3,6 +3,11 @@ class ApplicationController < ActionController::Base
def results_table
if (!session[:results])
session[:results] = {}
+ result = Result.new()
+ result.useragent = request.env['HTTP_USER_AGENT']
+ result.results = ActiveSupport::JSON::encode({})
+ result.save()
+ session[:dbResult] = result
end
session[:results]
end
@@ -11,6 +16,11 @@ def set_result(id, value)
results_table[id.to_s] = value
end
+ def save_results
+ session[:dbResult].update_attributes({ :results => ActiveSupport::JSON::encode(results_table), :total => results_table.length,
+ :success => results_table.count{|c| c[1] } })
+ end
+
def replace_host(value)
port = (request.port == 80) ? "" : (":" + request.port.to_s)
value.gsub("{host}", request.host + port).gsub(
View
4 app/controllers/home_controller.rb
@@ -3,6 +3,10 @@ def index
@testcase_json = replace_host(TestCase.all.sort{|x,y| x.id <=> y.id}.to_json)
end
+ def results
+ @results = Result.find(:all, :order => "id desc", :limit => 5).reverse
+ end
+
def about
end
View
1  app/controllers/test_controller.rb
@@ -25,6 +25,7 @@ def load
def results
@results = results_table
+ save_results
respond_to do |format|
format.json { render :json => @results }
end
View
2  app/models/result.rb
@@ -0,0 +1,2 @@
+class Result < ActiveRecord::Base
+end
View
5 app/views/home/results.html.erb
@@ -0,0 +1,5 @@
+<ul>
+<% @results.each do |result| %>
+ <li><b><%= result.success %>/<%= result.total %></b> - <%= result.useragent %></li>
+<% end %>
+</ul>
View
1  config/routes.rb
@@ -3,6 +3,7 @@
get "home/index"
get "home/about"
+ get "home/results"
match "test/pass/:id" => "test#pass"
View
12 db/migrate/20120906194114_create_results.rb
@@ -0,0 +1,12 @@
+class CreateResults < ActiveRecord::Migration
+ def change
+ create_table :results do |t|
+ t.string :useragent
+ t.string :results
+ t.integer :total
+ t.integer :success
+
+ t.timestamps
+ end
+ end
+end
View
11 db/schema.rb
@@ -10,7 +10,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120904203141) do
+ActiveRecord::Schema.define(:version => 20120906194114) do
+
+ create_table "results", :force => true do |t|
+ t.string "useragent"
+ t.string "results"
+ t.integer "total"
+ t.integer "success"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
View
13 test/fixtures/results.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ useragent: MyString
+ results: MyString
+ total: 1
+ success: 1
+
+two:
+ useragent: MyString
+ results: MyString
+ total: 1
+ success: 1
View
7 test/unit/result_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ResultTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.