deployments-app 0.0.1 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +2 -1
  2. data/Gemfile +21 -4
  3. data/Gemfile.lock +266 -0
  4. data/Guardfile +3 -0
  5. data/Rakefile +2 -0
  6. data/config.ru +5 -0
  7. data/config/deployments.yml.example +6 -0
  8. data/deployments-app.gemspec +3 -0
  9. data/features/deployments/view_deployments.feature +3 -0
  10. data/features/home/view_home.feature +22 -0
  11. data/features/pivotal_tracker/view_pivotal_tracker_story.feature +14 -0
  12. data/features/projects/new_project.feature +20 -0
  13. data/features/projects/view_deployments_by_project.feature +15 -0
  14. data/features/projects/view_projects.feature +12 -0
  15. data/features/step_definitions/common_steps.rb +4 -0
  16. data/features/step_definitions/deployments/view_deployments_by_project_steps.rb +11 -0
  17. data/features/step_definitions/deployments/view_deployments_steps.rb +17 -8
  18. data/features/step_definitions/home/view_home_steps.rb +16 -0
  19. data/features/step_definitions/pivotal_tracker/view_pivotal_tracker_steps.rb +16 -0
  20. data/features/step_definitions/projects/new_project_steps.rb +35 -0
  21. data/features/step_definitions/projects/view_projects_steps.rb +18 -0
  22. data/features/support/env.rb +8 -0
  23. data/lib/deployments-app.rb +19 -6
  24. data/lib/deployments-app/models/commit.rb +14 -16
  25. data/lib/deployments-app/models/deployment.rb +18 -21
  26. data/lib/deployments-app/models/project.rb +9 -13
  27. data/lib/deployments-app/routes/authentication.rb +1 -3
  28. data/lib/deployments-app/routes/extensions.rb +1 -3
  29. data/lib/deployments-app/routes/projects.rb +28 -0
  30. data/lib/deployments-app/routes/root.rb +7 -2
  31. data/lib/deployments-app/server.rb +13 -0
  32. data/lib/deployments-app/version.rb +1 -1
  33. data/lib/deployments-app/views/deployments/index.haml +13 -5
  34. data/lib/deployments-app/views/layouts/application.haml +39 -0
  35. data/lib/deployments-app/views/projects/index.haml +10 -0
  36. data/lib/deployments-app/views/projects/new.haml +7 -0
  37. data/public/css/bootstrap-responsive.min.css +9 -0
  38. data/public/css/bootstrap.min.css +622 -0
  39. data/public/img/glyphicons-halflings-white.png +0 -0
  40. data/public/img/glyphicons-halflings.png +0 -0
  41. data/public/js/bootstrap.min.js +6 -0
  42. data/public/js/jquery.min.js +4 -0
  43. data/spec/factories/commits.rb +1 -1
  44. data/spec/factories/deployments.rb +14 -2
  45. data/spec/factories/projects.rb +3 -2
  46. data/spec/models/commit_spec.rb +1 -3
  47. data/spec/models/deployment_spec.rb +13 -27
  48. data/spec/models/project_spec.rb +16 -7
  49. data/spec/routes/projects_spec.rb +31 -0
  50. data/spec/routes/root_spec.rb +50 -0
  51. data/spec/spec_helper.rb +15 -2
  52. data/spec/support/data_mapper.rb +1 -4
  53. data/spec/support/factory_girl.rb +18 -0
  54. metadata +91 -5
  55. data/config/database.yml.example +0 -6
  56. data/spec/routes/deployments_spec.rb +0 -20
@@ -0,0 +1,15 @@
1
+ Feature: View deployments following by name of the project
2
+ In order to view deployments
3
+ As an user
4
+ I want to be able navigate to the selected project to see deployments from the projects list page
5
+
6
+ Background:
7
+ Given I have project with deployments
8
+
9
+ When I am on the projects page
10
+
11
+ Scenario: View deployments following by name
12
+ When I follow by name of the project
13
+ Then I should see deployments of staging
14
+ And I should see commits that was deployed to the staging
15
+
@@ -0,0 +1,12 @@
1
+ Feature: View projects
2
+ In order to view existing projects in the app
3
+ As an user
4
+ I want to be able to open projects page and see list of projects
5
+
6
+ Background:
7
+ Given I have few projects
8
+
9
+ Scenario: View list of projects
10
+ When I am on the projects page
11
+ Then I should see list of projects
12
+
@@ -0,0 +1,4 @@
1
+ When /show me the page/ do
2
+ save_and_open_page
3
+ end
4
+
@@ -0,0 +1,11 @@
1
+ include Deployments::App
2
+
3
+ Given /^I have project with deployments$/ do
4
+ @project = create(:project)
5
+ @deployment = create(:deployment_with_commits, :env => 'staging', :project => @project)
6
+ end
7
+
8
+ When /^I follow by name of the project$/ do
9
+ click_link @project.name
10
+ end
11
+
@@ -1,6 +1,7 @@
1
+ include Deployments::App
2
+
1
3
  Given /^I have already deployed project to the (staging|production)$/ do |env|
2
- @deployment = build(:deployment_with_commits, :env => env, :project => @project)
3
- @deployment.save
4
+ @deployment = create(:deployment_with_commits, :env => env, :project => @project)
4
5
  end
5
6
 
6
7
  When /^I am on the deployments page$/ do
@@ -8,13 +9,13 @@ When /^I am on the deployments page$/ do
8
9
  end
9
10
 
10
11
  Then /^I should see deployments of (staging|production)$/ do |env|
11
- save_and_open_page
12
+ deployment = Deployment.first(:env => env)
12
13
 
13
- within('#deployments') do
14
- find('.env').should have_content(@deployment.env)
15
- find('.host_name').should have_content(@deployment.host_name)
16
- find('.author').should have_content(@deployment.author)
17
- find('.version').should have_content(@deployment.version)
14
+ within("#deployments #deployments_app_deployment_#{deployment.id}") do
15
+ find('.env').should have_content(deployment.env)
16
+ find('.host_name').should have_content(deployment.host_name)
17
+ find('.author').should have_content(deployment.author)
18
+ find('.version').should have_content(deployment.version)
18
19
  end
19
20
  end
20
21
 
@@ -22,3 +23,11 @@ Given /^I have a project$/ do
22
23
  @project = create(:project)
23
24
  end
24
25
 
26
+ Then /^I should see commits that was deployed to the (staging|production)$/ do |env|
27
+ deployment = Deployment.first(:env => env)
28
+
29
+ within("#deployments .commits") do
30
+ find('.message').should have_content('Added file')
31
+ end
32
+ end
33
+
@@ -0,0 +1,16 @@
1
+ When /^I am on the home page$/ do
2
+ visit '/projects'
3
+ end
4
+
5
+ When /^I click on the logo of the website$/ do
6
+ click_on "Deployments"
7
+ end
8
+
9
+ Then /^I should be on the home page$/ do
10
+ current_path.should match(/\/projects/)
11
+ end
12
+
13
+ When /^I click on the home tab$/ do
14
+ click_on "Home"
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ Given /^I have a deployments with pivotal tracker stories$/ do
2
+ pending # express the regexp above with the code you wish you had
3
+ end
4
+
5
+ When /^I am on the project page$/ do
6
+ pending # express the regexp above with the code you wish you had
7
+ end
8
+
9
+ Then /^I should see ids of pivotal tracker stories$/ do
10
+ pending # express the regexp above with the code you wish you had
11
+ end
12
+
13
+ Then /^I should be abe to navigate following id$/ do
14
+ pending # express the regexp above with the code you wish you had
15
+ end
16
+
@@ -0,0 +1,35 @@
1
+ include Deployments::App
2
+
3
+ Given /^I am on the new project page$/ do
4
+ visit '/projects/new'
5
+ end
6
+
7
+ When /^I fill all required fields$/ do
8
+ fill_in 'Name', :with => "Tetris"
9
+ end
10
+
11
+ When /^I save changes$/ do
12
+ click_on "Save"
13
+ end
14
+
15
+ Then /^I should see new project in the list$/ do
16
+ project = Project.last
17
+
18
+ within '#projects' do
19
+ find('.name').should have_content(project.name)
20
+ find('.api_key').should have_content(project.api_key)
21
+ end
22
+ end
23
+
24
+ When /^I don't fill one required field$/ do
25
+ fill_in 'Name', :with => ''
26
+ end
27
+
28
+ Then /^I should see error notification$/ do
29
+ pending # express the regexp above with the code you wish you had
30
+ end
31
+
32
+ When /^I click on the new project button$/ do
33
+ click_on "New"
34
+ end
35
+
@@ -0,0 +1,18 @@
1
+ Given /^I have few projects$/ do
2
+ @projects = []
3
+ 2.times { @projects << create(:project) }
4
+ end
5
+
6
+ When /^I am on the projects page$/ do
7
+ visit '/projects'
8
+ end
9
+
10
+ Then /^I should see list of projects$/ do
11
+ @projects.each do |project|
12
+ within("#projects #deployments_app_project_#{project.id}") do
13
+ find('.name').should have_content(project.name)
14
+ find('.api_key').should have_content(project.api_key)
15
+ end
16
+ end
17
+ end
18
+
@@ -9,6 +9,7 @@ require 'factory_girl'
9
9
 
10
10
  Dir[File.join(File.dirname(__FILE__), "../../spec/factories/*.rb")].each {|f| require f}
11
11
  require File.join(File.dirname(__FILE__), '../../spec/support/data_mapper')
12
+ require File.join(File.dirname(__FILE__), '../../spec/support/factory_girl')
12
13
 
13
14
  Capybara.app = Deployments::App::Server
14
15
 
@@ -17,3 +18,10 @@ World(RSpec::Expectations)
17
18
  World(RSpec::Matchers)
18
19
  World(FactoryGirl::Syntax::Methods)
19
20
 
21
+ begin
22
+ require 'database_cleaner'
23
+ require 'database_cleaner/cucumber'
24
+ DatabaseCleaner.strategy = :truncation
25
+ rescue NameError
26
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
27
+ end
@@ -1,18 +1,31 @@
1
1
  require 'rubygems'
2
- require 'data_mapper'
2
+
3
+ require 'dm-core'
4
+ require 'dm-validations'
5
+ require 'dm-migrations'
6
+ require 'dm-transactions'
7
+ require 'dm-serializer'
8
+ require 'dm-timestamps'
9
+ require 'dm-types'
10
+ require 'dm-constraints'
11
+
3
12
  require 'sinatra'
4
13
 
5
14
  require "deployments-app/version"
15
+
6
16
  require 'deployments-app/models/commit'
7
17
  require 'deployments-app/models/deployment'
8
18
  require 'deployments-app/models/project'
9
19
 
10
- require 'deployments-app/routes/authentication'
11
- require 'deployments-app/routes/root'
12
- require 'deployments-app/routes/extensions'
13
- require 'deployments-app/server'
14
-
15
20
  module Deployments
16
21
  module App
22
+ module Routes
23
+ autoload :Extensions, 'deployments-app/routes/extensions'
24
+ autoload :Root, 'deployments-app/routes/root'
25
+ autoload :Projects, 'deployments-app/routes/projects'
26
+ autoload :Authentication, 'deployments-app/routes/authentication'
27
+ end
28
+
29
+ autoload :Server, 'deployments-app/server'
17
30
  end
18
31
  end
@@ -1,29 +1,27 @@
1
1
  module Deployments
2
2
  module App
3
- module Models
4
- class Commit
5
- include DataMapper::Resource
3
+ class Commit
4
+ include DataMapper::Resource
6
5
 
7
- property :id, Serial
6
+ property :id, Serial
8
7
 
9
- property :sha, String, :required => true
10
- validates_presence_of :sha
8
+ property :sha, String, :required => true
9
+ validates_presence_of :sha
11
10
 
12
- property :message, Text, :required => true
13
- validates_presence_of :message
11
+ property :message, Text, :required => true
12
+ validates_presence_of :message
14
13
 
15
- property :created_at, DateTime, :required => true
16
- validates_presence_of :created_at
14
+ property :created_at, DateTime, :required => true
15
+ validates_presence_of :created_at
17
16
 
18
- has n, :deployments, :through => Resource
17
+ has n, :deployments, :through => Resource
19
18
 
20
- def self.find_by_sha_or_create(commit)
21
- existing = first(:sha => commit[:sha])
19
+ def self.find_by_sha_or_create(commit)
20
+ existing = first(:sha => commit[:sha])
22
21
 
23
- return Commit.create(commit) unless existing
22
+ return Commit.create(commit) unless existing
24
23
 
25
- existing
26
- end
24
+ existing
27
25
  end
28
26
  end
29
27
  end
@@ -1,35 +1,32 @@
1
1
  module Deployments
2
2
  module App
3
- module Models
3
+ class Deployment
4
+ include DataMapper::Resource
4
5
 
5
- class Deployment
6
- include DataMapper::Resource
6
+ property :id, Serial
7
7
 
8
- property :id, Serial
8
+ property :author, String, :required => true
9
+ validates_presence_of :author
9
10
 
10
- property :author, String, :required => true
11
- validates_presence_of :author
11
+ property :env, String, :required => true
12
+ validates_presence_of :env
12
13
 
13
- property :env, String, :required => true
14
- validates_presence_of :env
14
+ property :host_name, String, :required => true
15
+ validates_presence_of :host_name
15
16
 
16
- property :host_name, String, :required => true
17
- validates_presence_of :host_name
17
+ property :version, String, :required => true
18
+ validates_presence_of :version
18
19
 
19
- property :version, String, :required => true
20
- validates_presence_of :version
20
+ attr_accessor :commit_attributes
21
+ validates_presence_of :commit_attributes
21
22
 
22
- attr_accessor :commit_attributes
23
- validates_presence_of :commit_attributes
23
+ belongs_to :project
24
24
 
25
- belongs_to :project
25
+ has n, :commits, :through => Resource
26
26
 
27
- has n, :commits, :through => Resource
28
-
29
- before :save do
30
- self.commit_attributes.each do |commit|
31
- self.commits << Commit.find_by_sha_or_create(commit)
32
- end
27
+ before :create do
28
+ self.commit_attributes.each do |sha, commit|
29
+ self.commits << Commit.find_by_sha_or_create(commit.merge(:sha => sha))
33
30
  end
34
31
  end
35
32
  end
@@ -2,23 +2,19 @@ require 'uniquify'
2
2
 
3
3
  module Deployments
4
4
  module App
5
- module Models
6
- class Project
7
- include DataMapper::Resource
8
- include Uniquify
5
+ class Project
6
+ include DataMapper::Resource
7
+ include Uniquify
9
8
 
10
- property :id, Serial
9
+ property :id, Serial
11
10
 
12
- property :name, String, :required => true
13
- validates_presence_of :name
11
+ property :name, String
12
+ validates_presence_of :name
14
13
 
15
- property :api_key, String, :required => true
16
- uniquify :api_key
17
- validates_presence_of :api_key
18
- validates_uniqueness_of :api_key
14
+ property :api_key, String
15
+ uniquify :api_key
19
16
 
20
- has n, :deployments
21
- end
17
+ has n, :deployments
22
18
  end
23
19
  end
24
20
  end
@@ -2,10 +2,8 @@ module Deployments
2
2
  module App
3
3
  module Routes
4
4
  class Authentication < Sinatra::Base
5
- include Deployments::App::Models
6
-
7
5
  before '/deployments' do
8
- projects = Project.count(:api_key => params[:api_key])
6
+ projects = Project.all(:api_key => params[:api_key]).count
9
7
 
10
8
  return halt(401) if projects.zero?
11
9
  end
@@ -2,15 +2,13 @@ module Deployments
2
2
  module App
3
3
  module Routes
4
4
  module Extensions
5
-
6
5
  def self.included(base)
7
6
  base.class_eval do
8
7
  def current_project
9
- @project ||= Deployments::App::Models::Project.first(:api_key => params[:api_key])
8
+ @project ||= Project.first(:api_key => params[:api_key])
10
9
  end
11
10
  end
12
11
  end
13
-
14
12
  end
15
13
  end
16
14
  end
@@ -0,0 +1,28 @@
1
+ module Deployments
2
+ module App
3
+ module Routes
4
+ class Projects < Sinatra::Base
5
+ set :views, File.expand_path(settings.root + "/../views/projects")
6
+ set :haml, :layout => :"../layouts/application"
7
+
8
+ get '/projects' do
9
+ @projects = Project.all
10
+
11
+ haml :index
12
+ end
13
+
14
+ get '/projects/new' do
15
+ haml :new
16
+ end
17
+
18
+ post '/projects' do
19
+ @project = Project.new(params[:project])
20
+ @project.save
21
+
22
+ redirect '/projects'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -2,15 +2,20 @@ module Deployments
2
2
  module App
3
3
  module Routes
4
4
  class Root < Sinatra::Base
5
- include Deployments::App::Models
6
-
7
5
  set :views, File.expand_path(settings.root + "/../views/deployments")
6
+ set :haml, :layout => :"../layouts/application"
8
7
 
9
8
  get "/deployments" do
10
9
  @deployments = current_project.deployments
11
10
 
12
11
  haml :index
13
12
  end
13
+
14
+ post "/deployments" do
15
+ deployment = Deployment.new(params[:deployment])
16
+ deployment.project = current_project
17
+ deployment.save
18
+ end
14
19
  end
15
20
  end
16
21
  end