From 1f3620a3de1d5bde09fdd5429299edf05bdc1ad9 Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Thu, 5 Sep 2013 16:50:29 -0400 Subject: [PATCH 1/9] adding rspec and auto test runs --- Gemfile | 7 +++++++ Gemfile.lock | 9 +++++++++ Guardfile | 6 ++++++ test/functional/users_controller_test.rb | 6 +----- test/unit/benefits_test.rb | 5 ----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index c79f2f8..e425a6d 100755 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,9 @@ group :development, :test do gem 'rspec-rails' end +group :test do + gem 'rspec' +end # Gems used only for assets and not required # in production environments by default. @@ -52,9 +55,13 @@ gem 'jquery-rails' # Pow related gem gem 'powder' +<<<<<<< HEAD gem 'aruba' gem 'minitest', '~> 4.0', :require=> "minitest/autorun" +======= +#gem 'minitest' +>>>>>>> adding rspec and auto test runs # Deploy with Capistrano # gem 'capistrano' diff --git a/Gemfile.lock b/Gemfile.lock index 698a0df..9fa3b95 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -170,6 +170,14 @@ GEM rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) + rspec (2.14.0) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.2) + rspec-expectations (2.14.0) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.1) ruby2ruby (2.0.3) ruby_parser (~> 3.1) sexp_processor (~> 4.0) @@ -230,6 +238,7 @@ DEPENDENCIES rails (= 3.2.13) rb-fsevent rspec-rails + rspec sass-rails (~> 3.2.3) sqlite3 uglifier (>= 1.0.3) diff --git a/Guardfile b/Guardfile index b3ae7e6..de27bd7 100755 --- a/Guardfile +++ b/Guardfile @@ -20,3 +20,9 @@ guard 'livereload', host: "railsgoat.dev", port: '35727' do # Rails Assets Pipeline watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" } end + +guard :shell do + watch(%r{test/unit/.+\.rb}) { system("rake")} + watch(%r{test/functional/.+\.rb}) { system("rake")} + +end \ No newline at end of file diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 7d2d9b1..dfbee34 100755 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -1,9 +1,5 @@ require 'test_helper' class UsersControllerTest < ActionController::TestCase - test "should get new" do - get :new - assert_response :success - end -end +end \ No newline at end of file diff --git a/test/unit/benefits_test.rb b/test/unit/benefits_test.rb index 5104350..faca8c7 100644 --- a/test/unit/benefits_test.rb +++ b/test/unit/benefits_test.rb @@ -1,7 +1,2 @@ require 'test_helper' -class BenefitsTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end From 08c7800dff8b93c17ade79a0c0f2931533ec8200 Mon Sep 17 00:00:00 2001 From: mccabe615 Date: Fri, 6 Sep 2013 10:04:25 -0400 Subject: [PATCH 2/9] Update README.md Update readme with getting started instructions --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e5f57b..dfb5a6f 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ +## Getting Started ## +#### With Ruby, Rubygems, Git, and Bundler installed #### + + git clone https://github.com/OWASP/railsgoat.git + + cd railsgoat + + rvm use 1.9.3@railsgoat --create + + bundle + + rake db:create + + rake db:migrate + + rails s + + open http://0.0.0.0:3000 + + Start hacking!!! + ### Developer Note ###

Conversion to the OWASP Top 10, 2013 is under way. @@ -33,4 +54,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -


\ No newline at end of file +
From 0bb5fd06c159cba28e5be8d4b1de57e0a3c6d01d Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Fri, 6 Sep 2013 10:08:53 -0400 Subject: [PATCH 3/9] fixing Gemfile --- Gemfile | 4 +--- Gemfile.lock | 16 +++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index e425a6d..e69c6ab 100755 --- a/Gemfile +++ b/Gemfile @@ -55,13 +55,11 @@ gem 'jquery-rails' # Pow related gem gem 'powder' -<<<<<<< HEAD gem 'aruba' gem 'minitest', '~> 4.0', :require=> "minitest/autorun" -======= + #gem 'minitest' ->>>>>>> adding rspec and auto test runs # Deploy with Capistrano # gem 'capistrano' diff --git a/Gemfile.lock b/Gemfile.lock index 9fa3b95..d530641 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -159,9 +159,15 @@ GEM rb-fsevent (0.9.3) rdoc (3.12.2) json (~> 1.4) + rspec (2.14.0) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.2) rspec-core (2.14.4) rspec-expectations (2.14.0) diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.1) rspec-mocks (2.14.2) rspec-rails (2.14.0) actionpack (>= 3.0) @@ -170,14 +176,6 @@ GEM rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) - rspec (2.14.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.2) - rspec-expectations (2.14.0) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.1) ruby2ruby (2.0.3) ruby_parser (~> 3.1) sexp_processor (~> 4.0) @@ -237,8 +235,8 @@ DEPENDENCIES rack-livereload rails (= 3.2.13) rb-fsevent - rspec-rails rspec + rspec-rails sass-rails (~> 3.2.3) sqlite3 uglifier (>= 1.0.3) From 914e35e0dd7948c4b30857a9a6acaeac81c7b293 Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Fri, 6 Sep 2013 15:43:59 -0400 Subject: [PATCH 4/9] adding rspec-rails and guard-rspec --- Gemfile | 5 +---- Gemfile.lock | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index e69c6ab..aec2b0a 100755 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem 'foreman' group :development do gem 'brakeman' gem 'guard-brakeman' + gem 'guard-rspec' gem 'rb-fsevent' gem 'guard-shell' gem 'bundler-audit' @@ -25,10 +26,6 @@ group :development, :test do gem 'rspec-rails' end -group :test do - gem 'rspec' -end - # Gems used only for assets and not required # in production environments by default. group :assets do diff --git a/Gemfile.lock b/Gemfile.lock index d530641..d0e774c 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,6 +95,9 @@ GEM em-websocket (>= 0.2.0) guard (>= 1.5.0) multi_json (~> 1.0) + guard-rspec (2.5.4) + guard (>= 1.1) + rspec (~> 2.11) guard-shell (0.5.1) guard (>= 1.1.0) haml (4.0.2) @@ -159,16 +162,14 @@ GEM rb-fsevent (0.9.3) rdoc (3.12.2) json (~> 1.4) - rspec (2.14.0) + rspec (2.14.1) rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) rspec-core (2.14.2) - rspec-core (2.14.4) rspec-expectations (2.14.0) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.1) - rspec-mocks (2.14.2) rspec-rails (2.14.0) actionpack (>= 3.0) activesupport (>= 3.0) @@ -227,6 +228,7 @@ DEPENDENCIES gauntlt guard-brakeman guard-livereload + guard-rspec guard-shell jquery-fileupload-rails jquery-rails @@ -235,7 +237,6 @@ DEPENDENCIES rack-livereload rails (= 3.2.13) rb-fsevent - rspec rspec-rails sass-rails (~> 3.2.3) sqlite3 From dc3de592ea23d1b61d1dac69fec28d7dce5a2f45 Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Fri, 6 Sep 2013 15:44:40 -0400 Subject: [PATCH 5/9] init\'ing guard-rspec --- Guardfile | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Guardfile b/Guardfile index de27bd7..af80ae3 100755 --- a/Guardfile +++ b/Guardfile @@ -21,8 +21,25 @@ guard 'livereload', host: "railsgoat.dev", port: '35727' do watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" } end -guard :shell do - watch(%r{test/unit/.+\.rb}) { system("rake")} - watch(%r{test/functional/.+\.rb}) { system("rake")} -end \ No newline at end of file +guard 'rspec' do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^spec/support/(.+)\.rb$}) { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + + # Capybara features specs + watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } +end + From 69c180e845ffcb21e0a486334b59bc7fd9b8ec54 Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Fri, 6 Sep 2013 15:54:06 -0400 Subject: [PATCH 6/9] minor changes to spec_helper and user model --- app/models/user.rb | 2 ++ spec/spec_helper.rb | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7e92104..a9ecca8 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,6 +18,8 @@ class User < ActiveRecord::Base has_many :performance, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy + private + def full_name "#{self.first_name} #{self.last_name}" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9417bfa..d2cbea7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) -require 'minitest/autorun' require 'rspec/rails' require 'rspec/autorun' From 16d1150375733907f47003e3bfc571f2a681baa1 Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Fri, 6 Sep 2013 15:55:08 -0400 Subject: [PATCH 7/9] adding basic tests or user model, more to come --- spec/models/benefits_spec.rb | 1 + spec/models/paid_time_off_spec.rb | 14 ++++++++++++++ spec/models/user_spec.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 spec/models/benefits_spec.rb create mode 100644 spec/models/paid_time_off_spec.rb create mode 100644 spec/models/user_spec.rb diff --git a/spec/models/benefits_spec.rb b/spec/models/benefits_spec.rb new file mode 100644 index 0000000..f8ec369 --- /dev/null +++ b/spec/models/benefits_spec.rb @@ -0,0 +1 @@ +require 'spec_helper' diff --git a/spec/models/paid_time_off_spec.rb b/spec/models/paid_time_off_spec.rb new file mode 100644 index 0000000..2dba717 --- /dev/null +++ b/spec/models/paid_time_off_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper.rb' +=begin +describe "PaidTimeOff" do + user = User.new( + first_name: 'Tester', + last_name: 'MGee', + email: 'tester.mgee@gmail.com', + password: 'password', + password_confirmation: 'password' + ) + expect(user).to be_valid +end + +=end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..759d850 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper.rb' + +describe User do + it "can be instantiated" do + User.new.should be_an_instance_of(User) + end + + it "should require a email" do + User.new(:email => "").should_not be_valid + end + + it "should require valid email" do + User.new(:email => "tester@gmail.com@gmail.com").should_not be_valid + end + + it "should require unique email" do + user = User.all.first + User.new(:email => user.email).should_not be_valid + end + + it "name can be updated" do + new_name = "Bobby" + user = User.all.first + user.first_name = new_name + user.save! + User.all.first.first_name.should == new_name + end +end \ No newline at end of file From 5123d8ba770a07df0d18e910ceb814ce2b9aee8f Mon Sep 17 00:00:00 2001 From: mccabe615 Date: Fri, 6 Sep 2013 16:03:09 -0400 Subject: [PATCH 8/9] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index dfb5a6f..0740350 100755 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ You can view progress within the top-10-2013 branch. Then proceed with browsing the site as normal :thumbsup:
+### Build Info ### + +[![Code Climate](https://codeclimate.com/github/OWASP/railsgoat.png)](https://codeclimate.com/github/OWASP/railsgoat) + ### License Stuff ### The MIT License (MIT) From 9638d8137bee1650eb6578b2f5e2c88cb511b664 Mon Sep 17 00:00:00 2001 From: Michael McCabe Date: Tue, 10 Sep 2013 09:17:40 -0400 Subject: [PATCH 9/9] travis fix --- .travis.yml | 4 ++++ Gemfile | 1 + Gemfile.lock | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8c734ac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby +rvm: + - "1.9.3" +before_script: rake db:migrate diff --git a/Gemfile b/Gemfile index aec2b0a..72031de 100755 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ group :development do gem 'bundler-audit' gem 'guard-livereload' gem 'rack-livereload' + gem 'travis-lint' end gem 'gauntlt' diff --git a/Gemfile.lock b/Gemfile.lock index d0e774c..e82bd83 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,7 @@ GEM guard (>= 1.1.0) haml (4.0.2) tilt + hashr (0.0.22) highline (1.6.16) hike (1.2.2) http_parser.rb (0.5.3) @@ -202,6 +203,8 @@ GEM terminal-table (1.4.5) thor (0.18.1) tilt (1.3.7) + travis-lint (1.7.0) + hashr (~> 0.0.22) treetop (1.4.12) polyglot polyglot (>= 0.3.1) @@ -240,5 +243,6 @@ DEPENDENCIES rspec-rails sass-rails (~> 3.2.3) sqlite3 + travis-lint uglifier (>= 1.0.3) unicorn