delinquo 0.0.3

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +39 -0
  6. data/Rakefile +65 -0
  7. data/bin/delinquo +14 -0
  8. data/config/database.rb +18 -0
  9. data/config.ru +7 -0
  10. data/db/migrate/20130925071434_create_projects.rb +13 -0
  11. data/db/migrate/20130927101642_create_projects.rb +13 -0
  12. data/db/migrate/20130927101721_create_runs.rb +14 -0
  13. data/db/migrate/20130927104041_create_fails.rb +17 -0
  14. data/db/migrate/20130927161238_change_run_total_to_int.rb +5 -0
  15. data/db/migrate/20130927161545_change_run_total_to_string.rb +5 -0
  16. data/db/schema.rb +44 -0
  17. data/delinquo.gemspec +31 -0
  18. data/lib/delinquo/version.rb +3 -0
  19. data/lib/delinquo.rb +112 -0
  20. data/lib/public/css/bootstrap.css +4692 -0
  21. data/lib/public/css/bootstrap.min.css +9 -0
  22. data/lib/public/css/main.css +132 -0
  23. data/lib/public/images/changeable.svg +51 -0
  24. data/lib/public/images/cloud.svg +3 -0
  25. data/lib/public/images/rain.svg +7 -0
  26. data/lib/public/images/storm.svg +3 -0
  27. data/lib/public/images/sun.svg +3 -0
  28. data/lib/public/images/umbrella.svg +3 -0
  29. data/lib/public/index.html +9 -0
  30. data/lib/public/js/bootstrap.js +1966 -0
  31. data/lib/public/js/bootstrap.min.js +6 -0
  32. data/lib/views/index.erb +56 -0
  33. data/lib/views/layout.erb +16 -0
  34. data/lib/views/no_runs.erb +1 -0
  35. data/lib/views/not_a_project.erb +4 -0
  36. data/models/fail.rb +4 -0
  37. data/models/project.rb +38 -0
  38. data/models/run.rb +47 -0
  39. data/spec/api_spec.rb +141 -0
  40. data/spec/models/fail_spec.rb +18 -0
  41. data/spec/models/project_spec.rb +74 -0
  42. data/spec/models/run_spec.rb +82 -0
  43. data/spec/report_spec.rb +207 -0
  44. data/spec/spec_helper.rb +79 -0
  45. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a169eacd6f5bd76998affb6c386d8069125430e
4
+ data.tar.gz: b1388d354966ca8a1483ee169eef846bdb580fbe
5
+ SHA512:
6
+ metadata.gz: e0723535a80e9febeeb66b29da54421124a42f2ed863a9e41a1d539a55aba33ac3bab97ded1299ffec30be52372567470a570c67c565cffa1376e1e4fb4b6766
7
+ data.tar.gz: 67dff1e348cd3918830632ef16293741b7eb36acaccd55231c0ae9c1303e330bf0878ec12e3305d9a46a2ef936a988ecb3d31847552e7664ce9c25424e7d612c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rain.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Steven Cook
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Delinquo
2
+ #####*Commit a fault*
3
+
4
+ A really simple cucumber failure monitoring API and Gem.
5
+
6
+ ###Example report
7
+ [Onesport](http://delinquo.co.uk/report/onesport)
8
+
9
+ ###Getting Started
10
+
11
+ Add the 'delinquo-formatter' gem to your Gemfile
12
+ ```ruby
13
+ git 'https://github.com/bbc-sport/delinquo.git' do
14
+ gem 'delinquo-formatter'
15
+ end
16
+ ```
17
+
18
+ Add a new profile to ```cucumber.yml``` in the root of your cucumber project. This profile runs the Delinquo formatter to post to the API
19
+ and the pretty formatter for a useful console output.
20
+
21
+ ```
22
+ PROFILE_NAME: --format Cucumber::Formatter::Delinquo --out delinquo --format pretty delinquo_project=YOUR_PROJECT_NAME
23
+ ```
24
+
25
+ Bundle
26
+ ```
27
+ bundle install
28
+ ```
29
+
30
+ Run cucumber with the new profile
31
+ ```
32
+ bundle exec cucumber -p PROFILE_NAME
33
+ ```
34
+
35
+ Once the build has finished, visit ```http://delinquo.co.uk/report/YOUR_PROJECT_NAME```
36
+
37
+ ####Caveats
38
+
39
+ To use Delinquo as part of a CI build, ensure you have followed the [git setup for password caching](https://help.github.com/articles/set-up-git#set-up-git) set up
data/Rakefile ADDED
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'bundler/gem_tasks'
6
+
7
+ require 'sinatra/activerecord/rake'
8
+
9
+ require './lib/delinquo'
10
+
11
+ Delinquo::App
12
+
13
+ ActiveRecord::Base.logger = nil
14
+
15
+ namespace :database do
16
+ desc "Delete and create new databases"
17
+ task :start_from_scratch => [:delete_all, :create_all] do
18
+ puts 'So fresh and so clean :)'
19
+ end
20
+
21
+ desc "Delete all databases"
22
+ task :delete_all => [:delete_dev, :delete_test, :delete_production] do
23
+ puts 'All databases deleted'
24
+ end
25
+
26
+ desc "Create all new databases"
27
+ task :create_all => [:create_production, :create_test, :create_development] do
28
+ puts 'All databases created'
29
+ end
30
+
31
+ desc "Delete development database"
32
+ task :delete_dev do
33
+ sh 'rm -rf delinquo-dev.db'
34
+ puts 'delinquo-dev.db deleted'
35
+ end
36
+
37
+ desc "Delete test database"
38
+ task :delete_test do
39
+ sh 'rm -rf delinquo-test.db'
40
+ puts 'delinquo-test.db deleted'
41
+ end
42
+
43
+ desc "Delete production database"
44
+ task :delete_production do
45
+ sh 'rm -rf delinquo-production.db'
46
+ puts 'delinquo-production.db deleted'
47
+ end
48
+
49
+ desc "Create production database"
50
+ task :create_production do
51
+ sh 'RACK_ENV=production rake db:schema:load'
52
+ end
53
+
54
+ desc "Create test database"
55
+ task :create_test do
56
+ sh 'RACK_ENV=test rake db:schema:load'
57
+ end
58
+
59
+ desc "Create development database"
60
+ task :create_development do
61
+ sh 'RACK_ENV=development rake db:schema:load'
62
+ end
63
+
64
+ end
65
+
data/bin/delinquo ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/delinquo'
4
+ require 'thin'
5
+
6
+ rackup_file = "#{File.dirname(__FILE__)}/../config.ru"
7
+
8
+ `rake database:start_from_scratch`
9
+
10
+ argv = ARGV
11
+ argv << ["-R", rackup_file] unless ARGV.include?("-R")
12
+ argv << ["-p", "2003"] unless ARGV.include?("-p")
13
+ argv << ["-e", "production"] unless ARGV.include?("-e")
14
+ Thin::Runner.new(argv.flatten).run!
@@ -0,0 +1,18 @@
1
+ configure :development do
2
+ set :database_extras, {:pool => 5, :timeout => 500}
3
+ set :database, 'sqlite3:///delinquo-dev.db'
4
+ end
5
+
6
+ configure :test do
7
+ set :database_extras, {:pool => 5, :timeout => 500}
8
+ set :database, 'sqlite3:///delinquo-test.db'
9
+ end
10
+
11
+ configure :production do
12
+ set :database_extras, {:pool => 5, :timeout => 500}
13
+ set :database, 'sqlite3:///delinquo-production.db'
14
+ end
15
+
16
+
17
+ ActiveRecord::Base.logger = nil
18
+
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require './lib/delinquo'
6
+
7
+ Delinquo::App.run!
@@ -0,0 +1,13 @@
1
+ class CreateProjects < ActiveRecord::Migration
2
+ def up
3
+ create_table :projects do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ add_index :projects, :name, unique: true
8
+ end
9
+
10
+ def down
11
+ drop_table :projects
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreateProjects < ActiveRecord::Migration
2
+ def up
3
+ create_table :projects do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ add_index :projects, :name, unique: true
8
+ end
9
+
10
+ def down
11
+ drop_table :projects
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ class CreateRuns < ActiveRecord::Migration
2
+ def up
3
+ create_table :runs do |t|
4
+ t.string :total
5
+ t.references :project
6
+ t.timestamps
7
+ end
8
+ add_index :runs, :project_id
9
+ end
10
+
11
+ def down
12
+ drop_table :runs
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ class CreateFails < ActiveRecord::Migration
2
+ def up
3
+ create_table :fails do |t|
4
+ t.string :feature
5
+ t.string :scenario
6
+ t.string :step
7
+ t.string :line
8
+ t.references :run
9
+ t.timestamps
10
+ end
11
+ add_index :fails, :run_id
12
+ end
13
+
14
+ def down
15
+ drop_table :fails
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeRunTotalToInt < ActiveRecord::Migration
2
+ def change
3
+ change_column :runs, :total, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeRunTotalToString < ActiveRecord::Migration
2
+ def change
3
+ change_column :runs, :total, :string
4
+ end
5
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,44 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 20130927161545) do
14
+
15
+ create_table "fails", force: true do |t|
16
+ t.string "feature"
17
+ t.string "scenario"
18
+ t.string "step"
19
+ t.string "line"
20
+ t.integer "run_id"
21
+ t.datetime "created_at"
22
+ t.datetime "updated_at"
23
+ end
24
+
25
+ add_index "fails", ["run_id"], name: "index_fails_on_run_id"
26
+
27
+ create_table "projects", force: true do |t|
28
+ t.string "name"
29
+ t.datetime "created_at"
30
+ t.datetime "updated_at"
31
+ end
32
+
33
+ add_index "projects", ["name"], name: "index_projects_on_name", unique: true
34
+
35
+ create_table "runs", force: true do |t|
36
+ t.string "total"
37
+ t.integer "project_id"
38
+ t.datetime "created_at"
39
+ t.datetime "updated_at"
40
+ end
41
+
42
+ add_index "runs", ["project_id"], name: "index_runs_on_project_id"
43
+
44
+ end
data/delinquo.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delinquo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "delinquo"
8
+ spec.version = Delinquo::VERSION
9
+ spec.authors = ["Steven Cook"]
10
+ spec.email = ["stevenjamescook@gmail.com"]
11
+ spec.description = %q{Commit a fault}
12
+ spec.summary = %q{A really simple cucumber failure monitoring api}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ["delinquo"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'thin'
25
+ spec.add_dependency 'sinatra'
26
+ spec.add_dependency 'sinatra-activerecord'
27
+ spec.add_dependency 'sqlite3'
28
+ spec.add_dependency 'json'
29
+ spec.add_dependency 'rake'
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module Delinquo
2
+ VERSION = "0.0.3"
3
+ end
data/lib/delinquo.rb ADDED
@@ -0,0 +1,112 @@
1
+ require 'sinatra'
2
+ require 'sinatra/activerecord'
3
+
4
+ # require_relative '../config/database'
5
+
6
+ configure :development do
7
+ set :database_extras, {:pool => 5, :timeout => 500}
8
+ set :database, 'sqlite3:///delinquo-dev.db'
9
+ end
10
+
11
+ configure :test do
12
+ set :database_extras, {:pool => 5, :timeout => 500}
13
+ set :database, 'sqlite3:///delinquo-test.db'
14
+ end
15
+
16
+ configure :production do
17
+ set :database_extras, {:pool => 5, :timeout => 500}
18
+ set :database, 'sqlite3:///delinquo-production.db'
19
+ end
20
+
21
+
22
+ require_relative '../models/project'
23
+ require_relative '../models/fail'
24
+ require_relative '../models/run'
25
+
26
+ module Delinquo
27
+
28
+ class App < Sinatra::Base
29
+
30
+ # TODO: set public_folder properly
31
+ # set :static, true
32
+ # set :public_folder, File.expand_path('..', __FILE__) + '/public'
33
+
34
+ get '/' do
35
+ send_file File.expand_path('..', __FILE__) + '/public/index.html'
36
+ end
37
+
38
+ get '/env' do
39
+ "Env is set to " + settings.environment.to_s
40
+ end
41
+
42
+ get '/projects' do
43
+ content_type :json
44
+ projects = Project.all.pluck(:name)
45
+ projects.to_json
46
+ end
47
+
48
+ get '/project/:name' do | name |
49
+ content_type :json
50
+ project = Project.where(name: name)
51
+ if project.exists?
52
+ halt 200, project.first.runs.to_json(except: [:id, :project_id], include: { fails: { except: [:id, :run_id]}})
53
+ end
54
+ halt 404, {'Warning' => "project not found with the name #{name}"}, ""
55
+ end
56
+
57
+ post '/project/:name' do | name |
58
+ if create_project name
59
+ halt 201
60
+ end
61
+ halt 409, {'Warning' => "project already exists with the name #{name}"}, ""
62
+ end
63
+
64
+ post '/project/:name/run' do | name |
65
+ json = JSON.parse(request.body.read)
66
+ total_tests = json['total']
67
+ fails = json['fails']
68
+ project = Project.where(name: name)
69
+ if project.exists?
70
+ if project.first.runs.count == 10
71
+ project.first.runs.first.delete
72
+ end
73
+ begin
74
+ run = project.first.runs.create! total: total_tests
75
+ fails.each do | fail |
76
+ run.fails.create! fail
77
+ end
78
+ halt 201
79
+ rescue
80
+ halt 400
81
+ end
82
+ end
83
+ halt 404, {'Warning' => "project not found with the name #{name}"}, ""
84
+ end
85
+
86
+ get '/report/:name' do | name |
87
+ @name = params[:name].capitalize
88
+ project = Project.where(name: name)
89
+ if project.exists?
90
+ if project.first.runs.count == 0
91
+ halt 200, (erb :no_runs)
92
+ end
93
+ @forecast = project.first.forecast
94
+ @top_fail = project.first.top_fail
95
+ @runs = project.first.runs
96
+ @runs ||= []
97
+ halt 200, (erb :index)
98
+ end
99
+ halt 200, (erb :not_a_project)
100
+ end
101
+
102
+ def create_project(name)
103
+ unless Project.where(name: name).exists?
104
+ if Project.new(name: name).save!
105
+ return true
106
+ end
107
+ end
108
+ false
109
+ end
110
+ end
111
+
112
+ end