deployments-app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
18
+ config/database.yml
19
+ *.html
20
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm use --create 1.9.3@deployments-app
2
+
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'sinatra'
6
+ gem 'heroku'
7
+ gem 'datamapper'
8
+ gem 'uniquify', :git => "git@github.com:oivoodoo/uniquify.git"
9
+ gem 'data_mapper'
10
+ gem 'haml'
11
+
12
+ group :test do
13
+ gem 'rspec'
14
+ gem 'cucumber'
15
+ gem 'capybara'
16
+ gem 'capybara-webkit'
17
+ gem 'ruby_gntp'
18
+ gem 'factory_girl'
19
+ gem 'shoulda'
20
+ gem 'guard-rspec'
21
+ gem 'guard-cucumber'
22
+ gem 'rack-test'
23
+ gem 'dm-rspec'
24
+ gem 'dm-mysql-adapter'
25
+ end
26
+
27
+ group :development do
28
+ gem 'debugger'
29
+ end
30
+
data/Guardfile ADDED
@@ -0,0 +1,17 @@
1
+ guard 'rspec', :cli => '--format documentation', :version => 2, :all_after_pass => false, :keep_failed => false do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^spec/.+\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
5
+ watch(%r{^lib/deployments-app/models/(.+)\.rb$}) { "spec/models/" }
6
+ watch(%r{^lib/deployments-app/(.+)\.rb$}) { "spec" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
10
+ guard 'cucumber',:all_after_pass => false do
11
+ watch(%r{^views/.+\.haml$}) { 'features' }
12
+ watch(%r{^lib/deployments-app/views/.+\.haml$}) { 'features' }
13
+ watch(%r{^features/.+\.feature$})
14
+ watch(%r{^features/support/.+$}) { 'features' }
15
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
16
+ end
17
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexandr Korsak
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,29 @@
1
+ # Deployments::App
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'deployments-app'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install deployments-app
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ test:
2
+ username: root
3
+ password:
4
+ database: deployments-app-test
5
+ host: localhost
6
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/deployments-app/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexandr Korsak"]
6
+ gem.email = ["alex.korsak@gmail.com"]
7
+ gem.description = %q{deployments - app it's a sinatra application, you can run it as standalone app on the heroku or attach to the existing rails application.}
8
+ gem.summary = %q{deployments - app it's a sinatra application, you can run it as standalone app on the heroku or attach to the existing rails application.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "deployments-app"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Deployments::App::VERSION
17
+
18
+ gem.add_dependency('sinatra')
19
+ end
20
+
@@ -0,0 +1,22 @@
1
+ Feature: View deployments
2
+ In order to view deployments information of the project
3
+ As an User
4
+ I want to be able to read deployment information for all releases
5
+
6
+ Background:
7
+ Given I have a project
8
+
9
+ Scenario: View deployments information of staging env
10
+ Given I have already deployed project to the staging
11
+
12
+ When I am on the deployments page
13
+ Then I should see deployments of staging
14
+
15
+ Scenario: View deployments information of production env
16
+ Given I have already deployed project to the staging
17
+ And I have already deployed project to the production
18
+
19
+ When I am on the deployments page
20
+ Then I should see deployments of production
21
+ And I should see deployments of staging
22
+
@@ -0,0 +1,24 @@
1
+ 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
+ end
5
+
6
+ When /^I am on the deployments page$/ do
7
+ visit "/deployments?api_key=#{@project.api_key}"
8
+ end
9
+
10
+ Then /^I should see deployments of (staging|production)$/ do |env|
11
+ save_and_open_page
12
+
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)
18
+ end
19
+ end
20
+
21
+ Given /^I have a project$/ do
22
+ @project = create(:project)
23
+ end
24
+
@@ -0,0 +1,19 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'deployments-app'
4
+
5
+ require 'capybara'
6
+ require 'capybara/cucumber'
7
+ require 'rspec'
8
+ require 'factory_girl'
9
+
10
+ Dir[File.join(File.dirname(__FILE__), "../../spec/factories/*.rb")].each {|f| require f}
11
+ require File.join(File.dirname(__FILE__), '../../spec/support/data_mapper')
12
+
13
+ Capybara.app = Deployments::App::Server
14
+
15
+ World(Capybara::DSL)
16
+ World(RSpec::Expectations)
17
+ World(RSpec::Matchers)
18
+ World(FactoryGirl::Syntax::Methods)
19
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'data_mapper'
3
+ require 'sinatra'
4
+
5
+ require "deployments-app/version"
6
+ require 'deployments-app/models/commit'
7
+ require 'deployments-app/models/deployment'
8
+ require 'deployments-app/models/project'
9
+
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
+ module Deployments
16
+ module App
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Deployments
2
+ module App
3
+ module Models
4
+ class Commit
5
+ include DataMapper::Resource
6
+
7
+ property :id, Serial
8
+
9
+ property :sha, String, :required => true
10
+ validates_presence_of :sha
11
+
12
+ property :message, Text, :required => true
13
+ validates_presence_of :message
14
+
15
+ property :created_at, DateTime, :required => true
16
+ validates_presence_of :created_at
17
+
18
+ has n, :deployments, :through => Resource
19
+
20
+ def self.find_by_sha_or_create(commit)
21
+ existing = first(:sha => commit[:sha])
22
+
23
+ return Commit.create(commit) unless existing
24
+
25
+ existing
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ module Deployments
2
+ module App
3
+ module Models
4
+
5
+ class Deployment
6
+ include DataMapper::Resource
7
+
8
+ property :id, Serial
9
+
10
+ property :author, String, :required => true
11
+ validates_presence_of :author
12
+
13
+ property :env, String, :required => true
14
+ validates_presence_of :env
15
+
16
+ property :host_name, String, :required => true
17
+ validates_presence_of :host_name
18
+
19
+ property :version, String, :required => true
20
+ validates_presence_of :version
21
+
22
+ attr_accessor :commit_attributes
23
+ validates_presence_of :commit_attributes
24
+
25
+ belongs_to :project
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
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,24 @@
1
+ require 'uniquify'
2
+
3
+ module Deployments
4
+ module App
5
+ module Models
6
+ class Project
7
+ include DataMapper::Resource
8
+ include Uniquify
9
+
10
+ property :id, Serial
11
+
12
+ property :name, String, :required => true
13
+ validates_presence_of :name
14
+
15
+ property :api_key, String, :required => true
16
+ uniquify :api_key
17
+ validates_presence_of :api_key
18
+ validates_uniqueness_of :api_key
19
+
20
+ has n, :deployments
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Deployments
2
+ module App
3
+ module Routes
4
+ class Authentication < Sinatra::Base
5
+ include Deployments::App::Models
6
+
7
+ before '/deployments' do
8
+ projects = Project.count(:api_key => params[:api_key])
9
+
10
+ return halt(401) if projects.zero?
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,18 @@
1
+ module Deployments
2
+ module App
3
+ module Routes
4
+ module Extensions
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ def current_project
9
+ @project ||= Deployments::App::Models::Project.first(:api_key => params[:api_key])
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,18 @@
1
+ module Deployments
2
+ module App
3
+ module Routes
4
+ class Root < Sinatra::Base
5
+ include Deployments::App::Models
6
+
7
+ set :views, File.expand_path(settings.root + "/../views/deployments")
8
+
9
+ get "/deployments" do
10
+ @deployments = current_project.deployments
11
+
12
+ haml :index
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,10 @@
1
+ module Deployments
2
+ module App
3
+ class Server < Sinatra::Base
4
+ use Routes::Authentication
5
+ use Routes::Root
6
+ end
7
+
8
+ Sinatra::Base.send(:include, Routes::Extensions)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Deployments
2
+ module App
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ #deployments
2
+ - @deployments.each do |deployment|
3
+ .env= deployment.env
4
+ .host_name= deployment.host_name
5
+ .author= deployment.author
6
+ .version= deployment.version
7
+
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ sequence(:message) { |n| "Added file #{n}" }
3
+ sequence(:sha) { |n| "12ff4a5775#{n}" }
4
+
5
+ factory :commit, :class => Deployments::App::Models::Commit do
6
+ sha
7
+ message
8
+ created_at { "2012-05-23 10:39:18 +0300" }
9
+ end
10
+ end
11
+
@@ -0,0 +1,14 @@
1
+ FactoryGirl.define do
2
+ factory :deployment, :class => Deployments::App::Models::Deployment do
3
+ author "Fred Watson"
4
+ env "staging"
5
+ host_name "staging.example.com"
6
+ version "1.0.3"
7
+ project
8
+ end
9
+
10
+ factory :deployment_with_commits, :parent => :deployment do
11
+ commit_attributes { [attributes_for(:commit), attributes_for(:commit)] }
12
+ end
13
+ end
14
+
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :project, :class => Deployments::App::Models::Project do
3
+ name 'Deployments portal'
4
+ api_key 'key'
5
+ end
6
+ end
7
+
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ include Deployments::App::Models
4
+
5
+ describe Commit do
6
+ it { should validate_presence_of :sha }
7
+ it { should validate_presence_of :message }
8
+ it { should validate_presence_of :created_at }
9
+
10
+ it { should have_many :deployments }
11
+ end
12
+
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ include Deployments::App::Models
4
+
5
+ describe Deployment do
6
+ it { should validate_presence_of :author }
7
+ it { should validate_presence_of :env }
8
+ it { should validate_presence_of :version }
9
+ it { should validate_presence_of :host_name }
10
+
11
+ it { should validate_presence_of :commit_attributes }
12
+ it { should have_many :commits }
13
+
14
+ it { should belong_to :project }
15
+
16
+ context "on create" do
17
+ let(:one) { attributes_for(:commit) }
18
+ let(:two) { attributes_for(:commit) }
19
+ let(:commit_attributes) { [one, two] }
20
+
21
+ before do
22
+ @deployment = build(:deployment,
23
+ :commit_attributes => commit_attributes)
24
+ end
25
+
26
+ it "should generate commits by raw commit attributes values" do
27
+ @deployment.save
28
+
29
+ @deployment.reload.commits == Commit.all
30
+ end
31
+
32
+ it "should connect just created commits with deployment" do
33
+ @deployment.save
34
+
35
+ @deployment.reload.commits.count.should == 2
36
+ end
37
+
38
+ context "with existing commit" do
39
+ let!(:commit) { create(:commit, :sha => one[:sha]) }
40
+
41
+ it "should not create new one commit by commit attributes" do
42
+ @deployment.save
43
+
44
+ @deployment.reload.commits.count.should == 2
45
+ end
46
+
47
+ it "should have existing commit in relation" do
48
+ @deployment.save
49
+
50
+ @deployment.reload.commits.should include(commit)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ include Deployments::App::Models
4
+
5
+ describe Project do
6
+ it { should validate_presence_of :name }
7
+
8
+ it { should validate_presence_of :api_key }
9
+ it { should validate_uniqueness_of :api_key }
10
+
11
+ it { should have_many(:deployments) }
12
+
13
+ context "on create" do
14
+ let(:project) { build(:project, :api_key => nil) }
15
+
16
+ it "should generate uniq api key" do
17
+ project.save
18
+
19
+ project.api_key.should be
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ include Deployments::App
4
+
5
+ describe Server do
6
+ let!(:project) { create(:project) }
7
+
8
+ context "viewing deployments page without api key" do
9
+ before { get '/deployments' }
10
+
11
+ it { last_response.status.should == 401 }
12
+ end
13
+
14
+ context "viewing deployments page with api key" do
15
+ before { get "/deployments?api_key=#{project.api_key}" }
16
+
17
+ it { last_response.should be_ok }
18
+ end
19
+ end
20
+
@@ -0,0 +1,18 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
3
+ require 'rubygems'
4
+ require 'deployments-app'
5
+ require 'factory_girl'
6
+ require 'dm-rspec'
7
+
8
+ Dir[File.expand_path("./spec/factories/*.rb")].each {|f| require f}
9
+
10
+ require_relative 'support/data_mapper'
11
+ require_relative 'support/rack_test'
12
+
13
+ RSpec.configure do |config|
14
+ config.include DataMapper::Matchers
15
+ config.include FactoryGirl::Syntax::Methods
16
+ config.include Rack::Test::Methods
17
+ end
18
+
@@ -0,0 +1,7 @@
1
+ config_file = File.join(File.dirname(__FILE__), "../../config/database.yml")
2
+ config = YAML.load(File.read(config_file))[ENV['RACK_ENV']]
3
+
4
+ DataMapper.setup(:default, "mysql://#{config['username']}@#{config['host']}/#{config['database']}")
5
+ DataMapper.finalize
6
+ DataMapper.auto_migrate!
7
+
@@ -0,0 +1,10 @@
1
+ require 'rack/test'
2
+
3
+ set :environment, :test
4
+ set :run, false
5
+ set :raise_errors, true
6
+ set :logging, false
7
+
8
+ def app
9
+ Deployments::App::Server
10
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployments-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexandr Korsak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: deployments - app it's a sinatra application, you can run it as standalone
31
+ app on the heroku or attach to the existing rails application.
32
+ email:
33
+ - alex.korsak@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .rspec
40
+ - .rvmrc
41
+ - Gemfile
42
+ - Guardfile
43
+ - LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - config/database.yml.example
47
+ - deployments-app.gemspec
48
+ - features/deployments/view_deployments.feature
49
+ - features/step_definitions/deployments/view_deployments_steps.rb
50
+ - features/support/env.rb
51
+ - lib/deployments-app.rb
52
+ - lib/deployments-app/models/commit.rb
53
+ - lib/deployments-app/models/deployment.rb
54
+ - lib/deployments-app/models/project.rb
55
+ - lib/deployments-app/routes/authentication.rb
56
+ - lib/deployments-app/routes/extensions.rb
57
+ - lib/deployments-app/routes/root.rb
58
+ - lib/deployments-app/server.rb
59
+ - lib/deployments-app/version.rb
60
+ - lib/deployments-app/views/deployments/index.haml
61
+ - spec/factories/commits.rb
62
+ - spec/factories/deployments.rb
63
+ - spec/factories/projects.rb
64
+ - spec/models/commit_spec.rb
65
+ - spec/models/deployment_spec.rb
66
+ - spec/models/project_spec.rb
67
+ - spec/routes/deployments_spec.rb
68
+ - spec/spec_helper.rb
69
+ - spec/support/data_mapper.rb
70
+ - spec/support/rack_test.rb
71
+ homepage: ''
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.23
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: deployments - app it's a sinatra application, you can run it as standalone
95
+ app on the heroku or attach to the existing rails application.
96
+ test_files:
97
+ - features/deployments/view_deployments.feature
98
+ - features/step_definitions/deployments/view_deployments_steps.rb
99
+ - features/support/env.rb
100
+ - spec/factories/commits.rb
101
+ - spec/factories/deployments.rb
102
+ - spec/factories/projects.rb
103
+ - spec/models/commit_spec.rb
104
+ - spec/models/deployment_spec.rb
105
+ - spec/models/project_spec.rb
106
+ - spec/routes/deployments_spec.rb
107
+ - spec/spec_helper.rb
108
+ - spec/support/data_mapper.rb
109
+ - spec/support/rack_test.rb