Compare commits
12 commits
github_rep
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
7fce3d67e8 | ||
|
b9e8dc5ef2 | ||
|
78a248286f | ||
|
2c28c02673 | ||
|
d4e44332ea | ||
|
a36060eb84 | ||
50266be909 | |||
4e0478429c | |||
4e62cb6593 | |||
5d948b79bd | |||
|
d6d2ad0b15 | ||
97b9a87d26 |
33 changed files with 348 additions and 30 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -28,3 +28,5 @@
|
||||||
|
|
||||||
# Ignore master key for decrypting credentials and more.
|
# Ignore master key for decrypting credentials and more.
|
||||||
/config/master.key
|
/config/master.key
|
||||||
|
|
||||||
|
/config/application.yml
|
||||||
|
|
|
@ -6,13 +6,10 @@ AllCops:
|
||||||
- bin/*
|
- bin/*
|
||||||
TargetRubyVersion: 2.4
|
TargetRubyVersion: 2.4
|
||||||
|
|
||||||
Gemspec/RequiredRubyVersion:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Naming/AccessorMethodName:
|
Naming/AccessorMethodName:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Style/RescueStandardError:
|
Lint/RescueWithoutErrorClass:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
|
|
8
Gemfile
8
Gemfile
|
@ -3,6 +3,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
||||||
|
|
||||||
ruby '2.4.1'
|
ruby '2.4.1'
|
||||||
|
|
||||||
|
gem 'figaro'
|
||||||
|
|
||||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||||
gem 'rails', '~> 5.2.0'
|
gem 'rails', '~> 5.2.0'
|
||||||
# Use sqlite3 as the database for Active Record
|
# Use sqlite3 as the database for Active Record
|
||||||
|
@ -38,16 +40,16 @@ gem 'bootsnap', '>= 1.1.0', require: false
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
|
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
|
||||||
gem 'web-console', '>= 3.3.0'
|
|
||||||
gem 'listen', '>= 3.0.5', '< 3.2'
|
gem 'listen', '>= 3.0.5', '< 3.2'
|
||||||
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
||||||
gem 'spring'
|
gem 'spring'
|
||||||
gem 'spring-watcher-listen', '~> 2.0.0'
|
gem 'spring-watcher-listen', '~> 2.0.0'
|
||||||
|
gem 'web-console', '>= 3.3.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
@ -59,4 +61,4 @@ group :test do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
|
||||||
|
|
|
@ -76,6 +76,8 @@ GEM
|
||||||
erubi (1.7.1)
|
erubi (1.7.1)
|
||||||
execjs (2.7.0)
|
execjs (2.7.0)
|
||||||
ffi (1.9.25)
|
ffi (1.9.25)
|
||||||
|
figaro (1.1.1)
|
||||||
|
thor (~> 0.14)
|
||||||
globalid (0.4.1)
|
globalid (0.4.1)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
i18n (1.0.1)
|
i18n (1.0.1)
|
||||||
|
@ -197,6 +199,7 @@ DEPENDENCIES
|
||||||
capybara (>= 2.15, < 4.0)
|
capybara (>= 2.15, < 4.0)
|
||||||
chromedriver-helper
|
chromedriver-helper
|
||||||
coffee-rails (~> 4.2)
|
coffee-rails (~> 4.2)
|
||||||
|
figaro
|
||||||
jbuilder (~> 2.5)
|
jbuilder (~> 2.5)
|
||||||
listen (>= 3.0.5, < 3.2)
|
listen (>= 3.0.5, < 3.2)
|
||||||
puma (~> 3.11)
|
puma (~> 3.11)
|
||||||
|
|
3
app/assets/javascripts/repository_github.coffee
Normal file
3
app/assets/javascripts/repository_github.coffee
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://coffeescript.org/
|
3
app/assets/stylesheets/repository_github.scss
Normal file
3
app/assets/stylesheets/repository_github.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// Place all the styles related to the RepositoryGithub controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
21
app/controllers/github_repository_controller.rb
Normal file
21
app/controllers/github_repository_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
class GithubRepositoryController < ApplicationController
|
||||||
|
def create
|
||||||
|
@software = Software.find(params[:software_id])
|
||||||
|
|
||||||
|
if @software.id == params[:repository][:software_id].to_i
|
||||||
|
@repository = GithubRepository.new(params.require(:repository).permit(:software_id, :name))
|
||||||
|
@repository.save
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to edit_software_path(@software)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@software = Software.find(params[:software_id])
|
||||||
|
@repository = GithubRepository.find(params[:id])
|
||||||
|
|
||||||
|
@repository.update(params.require(:repository).permit(:name)) if @software.id == @repository.software_id
|
||||||
|
|
||||||
|
redirect_to edit_software_path(@software)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,3 @@
|
||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
def index
|
def index; end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class SoftwaresController < ApplicationController
|
class SoftwaresController < ApplicationController
|
||||||
|
before_action :find_software, only: %i[show edit update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@softwares = Software.all
|
@softwares = Software.all
|
||||||
end
|
end
|
||||||
|
@ -7,19 +9,24 @@ class SoftwaresController < ApplicationController
|
||||||
@software = Software.new
|
@software = Software.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show; end
|
||||||
@software = Software.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@software = Software.find(params[:id])
|
case @software.repository_type
|
||||||
|
when 'Github'
|
||||||
|
if GithubRepository.exists?(software_id: @software)
|
||||||
|
@repository = GithubRepository.where(software_id: @software.id).take
|
||||||
|
@repository_form_path = software_github_repository_path(software_id: @software.id, id: @repository.id)
|
||||||
|
else
|
||||||
|
@repository = GithubRepository.new
|
||||||
|
@repository_form_path = software_github_repository_index_path(@software.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@software = Software.find(params[:id])
|
|
||||||
|
|
||||||
if @software.update(software_params)
|
if @software.update(software_params)
|
||||||
redirect_to @software
|
redirect_to edit_software_path(@software)
|
||||||
else
|
else
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
|
@ -29,14 +36,13 @@ class SoftwaresController < ApplicationController
|
||||||
@software = Software.new(software_params)
|
@software = Software.new(software_params)
|
||||||
|
|
||||||
if @software.save
|
if @software.save
|
||||||
redirect_to @software
|
redirect_to edit_software_path(@software)
|
||||||
else
|
else
|
||||||
render 'new'
|
render 'new'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@software = Software.find(params[:id])
|
|
||||||
@software.destroy
|
@software.destroy
|
||||||
|
|
||||||
redirect_to softwares_path
|
redirect_to softwares_path
|
||||||
|
@ -45,6 +51,10 @@ class SoftwaresController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def software_params
|
def software_params
|
||||||
params.require(:software).permit(:name, :website)
|
params.require(:software).permit(:name, :website, :repository_type)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_software
|
||||||
|
@software = Software.find(params[:id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
2
app/helpers/repository_github_helper.rb
Normal file
2
app/helpers/repository_github_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module RepositoryGithubHelper
|
||||||
|
end
|
6
app/models/branch.rb
Normal file
6
app/models/branch.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class Branch < ApplicationRecord
|
||||||
|
belongs_to :software
|
||||||
|
has_many :versions
|
||||||
|
validates :name, presence: true
|
||||||
|
validates :name, uniqueness: { scope: :software }
|
||||||
|
end
|
5
app/models/github_repository.rb
Normal file
5
app/models/github_repository.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class GithubRepository < ApplicationRecord
|
||||||
|
belongs_to :software
|
||||||
|
validates :name, presence: true, uniqueness: true
|
||||||
|
validates :software_id, presence: true, uniqueness: true
|
||||||
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
class Software < ApplicationRecord
|
class Software < ApplicationRecord
|
||||||
has_many :versions
|
has_many :branches
|
||||||
validates :name, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Version < ApplicationRecord
|
class Version < ApplicationRecord
|
||||||
belongs_to :software
|
belongs_to :branch
|
||||||
validates :number, presence: true
|
validates :number, presence: true
|
||||||
validates :date, presence: true
|
validates :date, presence: true
|
||||||
validates :number, uniqueness: { scope: :software }
|
validates :number, uniqueness: { scope: :branch }
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,33 @@
|
||||||
<%= form.label :website, class: 'uk-form-label' %><br>
|
<%= form.label :website, class: 'uk-form-label' %><br>
|
||||||
<%= form.text_field :website, class: 'uk-input' %>
|
<%= form.text_field :website, class: 'uk-input' %>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= form.label :repository_type, class: 'uk-form-label' %><br>
|
||||||
|
<%= form.select :repository_type, [nil, 'Github'], {}, class: 'uk-select' %>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
|
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% case @software.repository_type %>
|
||||||
|
<% when 'Github' %>
|
||||||
|
<h4>Github</h4>
|
||||||
|
<%= form_with(
|
||||||
|
scope: :repository,
|
||||||
|
url: @repository_form_path,
|
||||||
|
class: 'uk-form-horizontal uk-form-width-large',
|
||||||
|
model: @repository,
|
||||||
|
local: true
|
||||||
|
) do |form|
|
||||||
|
%>
|
||||||
|
<p>
|
||||||
|
<%= form.label :repository, class: 'uk-form-label' %><br>
|
||||||
|
<%= form.text_field :name, value: @repository.name, class: 'uk-input' %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= form.hidden_field :software_id, value: @software.id %>
|
||||||
|
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
<%= form.label :website, class: 'uk-form-label' %><br>
|
<%= form.label :website, class: 'uk-form-label' %><br>
|
||||||
<%= form.text_field :website, class: 'uk-input' %>
|
<%= form.text_field :website, class: 'uk-input' %>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= form.label :repository_type, class: 'uk-form-label' %><br>
|
||||||
|
<%= form.select :repository_type, [nil, 'Github'], {}, class: 'uk-select' %>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
|
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
<%= link_to 'Delete', software_path(@software), method: :delete, class: 'uk-icon-link', data: { confirm: 'Are you sure?' } %>
|
<%= link_to 'Delete', software_path(@software), method: :delete, class: 'uk-icon-link', data: { confirm: 'Are you sure?' } %>
|
||||||
</p>
|
</p>
|
||||||
<h3><%= @software.name %></h3>
|
<h3><%= @software.name %></h3>
|
||||||
|
<% @software.branches.order(name: :desc).each do |branch| %>
|
||||||
|
<h4><%= branch.name %></h4>
|
||||||
<table class="uk-table uk-table-striped">
|
<table class="uk-table uk-table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -12,10 +14,11 @@
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<% @software.versions.order(date: :desc).each do |version| %>
|
<% branch.versions.order(date: :desc).each do |version| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= version.number %></td>
|
<td><%= version.number %></td>
|
||||||
<td><%= version.date.strftime('%Y-%m-%d') %></td>
|
<td><%= version.date.strftime('%Y-%m-%d') %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
root 'home#index'
|
root 'home#index'
|
||||||
resources :softwares
|
resources :softwares do
|
||||||
|
resources :github_repository
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
class AddColumnRepositoryTypeInSoftware < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
change_table :softwares do |t|
|
||||||
|
t.string :repository_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
10
db/migrate/20180729191829_create_github_repositories.rb
Normal file
10
db/migrate/20180729191829_create_github_repositories.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class CreateGithubRepositories < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :github_repositories do |t|
|
||||||
|
t.string :name, uniqueness: true, null: false
|
||||||
|
t.references :software, uniqueness: true, foreign_key: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
10
db/migrate/20180804072602_create_branches.rb
Normal file
10
db/migrate/20180804072602_create_branches.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class CreateBranches < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :branches do |t|
|
||||||
|
t.string :name, null: false
|
||||||
|
t.references :software, foreign_key: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
8
db/migrate/20180805081706_change_reference_to_version.rb
Normal file
8
db/migrate/20180805081706_change_reference_to_version.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class ChangeReferenceToVersion < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
remove_reference :versions, :software, index: true, foreign_key: true
|
||||||
|
change_table :versions do |t|
|
||||||
|
t.references :branch, foreign_key: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
24
db/schema.rb
24
db/schema.rb
|
@ -10,22 +10,40 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2018_07_22_183046) do
|
ActiveRecord::Schema.define(version: 2018_08_05_081706) do
|
||||||
|
|
||||||
|
create_table "branches", force: :cascade do |t|
|
||||||
|
t.string "name", null: false
|
||||||
|
t.integer "software_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["software_id"], name: "index_branches_on_software_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "github_repositories", force: :cascade do |t|
|
||||||
|
t.string "name", null: false
|
||||||
|
t.integer "software_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["software_id"], name: "index_github_repositories_on_software_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "softwares", force: :cascade do |t|
|
create_table "softwares", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "website"
|
t.string "website"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "repository_type"
|
||||||
|
t.string "branch_pattern"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "versions", force: :cascade do |t|
|
create_table "versions", force: :cascade do |t|
|
||||||
t.string "number", null: false
|
t.string "number", null: false
|
||||||
t.datetime "date", null: false
|
t.datetime "date", null: false
|
||||||
t.integer "software_id"
|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["software_id"], name: "index_versions_on_software_id"
|
t.integer "branch_id"
|
||||||
|
t.index ["branch_id"], name: "index_versions_on_branch_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
72
lib/tasks/repositories.rake
Normal file
72
lib/tasks/repositories.rake
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
require 'net/https'
|
||||||
|
|
||||||
|
namespace :repositories do
|
||||||
|
def get_url_content(url, headers = {})
|
||||||
|
uri = URI.parse(url)
|
||||||
|
req = Net::HTTP::Get.new(uri)
|
||||||
|
|
||||||
|
headers.each do |header, value|
|
||||||
|
req[header] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
||||||
|
http.request(req)
|
||||||
|
end.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def branch(software_id, branches, version)
|
||||||
|
name = version.match(/^v?(?<branch>\d+\.\d+)(\.\d+)?$/)[:branch]
|
||||||
|
|
||||||
|
return branches[name] if branches.include?(name)
|
||||||
|
|
||||||
|
branch = Branch.new(
|
||||||
|
name: name,
|
||||||
|
software_id: software_id
|
||||||
|
)
|
||||||
|
branch.save
|
||||||
|
branches[name] = branch.id
|
||||||
|
branch.id
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Update version from github repositories'
|
||||||
|
task github: :environment do
|
||||||
|
headers = {
|
||||||
|
'Accept' => 'application/vnd.github.v3+json'
|
||||||
|
}
|
||||||
|
headers['Authorization'] = "token #{Figaro.env.github_token}" if Figaro.env.github_token
|
||||||
|
|
||||||
|
GithubRepository.all.each do |repo|
|
||||||
|
begin
|
||||||
|
software = Software.find(repo.software_id)
|
||||||
|
branches = software.branches.all.map { |b| [b.name, b.id] }.to_h
|
||||||
|
versions = software.branches.all.map { |b| b.versions.all.map(&:number) }
|
||||||
|
tags =
|
||||||
|
JSON.parse(
|
||||||
|
get_url_content(
|
||||||
|
"https://api.github.com/repos/#{repo.name}/tags",
|
||||||
|
headers
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
tags.each do |tag|
|
||||||
|
next if versions.include?(tag['name'])
|
||||||
|
|
||||||
|
branch_id = branch(software.id, branches, tag['name'])
|
||||||
|
date =
|
||||||
|
JSON.parse(
|
||||||
|
get_url_content(tag['commit']['url'], headers)
|
||||||
|
)['commit']['committer']['date']
|
||||||
|
|
||||||
|
puts Version.new(
|
||||||
|
branch_id: branch_id,
|
||||||
|
number: tag['name'],
|
||||||
|
date: date
|
||||||
|
).save
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
puts e.strace
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
require "test_helper"
|
require 'test_helper'
|
||||||
|
|
||||||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||||
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
|
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
|
||||||
|
|
63
test/controllers/github_repository_controller_test.rb
Normal file
63
test/controllers/github_repository_controller_test.rb
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class GithubRepositoryControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
test 'should not save repository without data' do
|
||||||
|
repository = GithubRepository.new
|
||||||
|
assert_not repository.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should not save repository without software_id' do
|
||||||
|
data = { name: 'test/test' }
|
||||||
|
repository = GithubRepository.new(data)
|
||||||
|
|
||||||
|
assert_not repository.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should not save repository if a repository already exist' do
|
||||||
|
data = {
|
||||||
|
name: 'test/test',
|
||||||
|
software_id: Software.find_by_name('Ruby on Rails').id
|
||||||
|
}
|
||||||
|
repository = GithubRepository.new(data)
|
||||||
|
|
||||||
|
assert_not repository.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should not save repository if a repository has the same name' do
|
||||||
|
data = {
|
||||||
|
name: 'rails/rails',
|
||||||
|
software_id: Software.find_by_name('Kaiho').id
|
||||||
|
}
|
||||||
|
repository = GithubRepository.new(data)
|
||||||
|
|
||||||
|
assert_not repository.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should save repository' do
|
||||||
|
data = {
|
||||||
|
name: 'kaiho/kaiho',
|
||||||
|
software_id: Software.find_by_name('Kaiho').id
|
||||||
|
}
|
||||||
|
repository = GithubRepository.new(data)
|
||||||
|
|
||||||
|
assert repository.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should not update repository if a repository has the same name' do
|
||||||
|
data = {
|
||||||
|
name: 'rails/rails'
|
||||||
|
}
|
||||||
|
repository = GithubRepository.find_by_name('ruby/ruby')
|
||||||
|
|
||||||
|
assert_not repository.update(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should update repository' do
|
||||||
|
data = {
|
||||||
|
name: 'rails/rails2'
|
||||||
|
}
|
||||||
|
repository = GithubRepository.find_by_name('rails/rails')
|
||||||
|
|
||||||
|
assert repository.update(data)
|
||||||
|
end
|
||||||
|
end
|
9
test/fixtures/branches.yml
vendored
Normal file
9
test/fixtures/branches.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: 1.0
|
||||||
|
software: two
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: 1.1
|
||||||
|
software: two
|
9
test/fixtures/github_repositories.yml
vendored
Normal file
9
test/fixtures/github_repositories.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: rails/rails
|
||||||
|
software: two
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: ruby/ruby
|
||||||
|
software: three
|
3
test/fixtures/softwares.yml
vendored
3
test/fixtures/softwares.yml
vendored
|
@ -7,3 +7,6 @@ one:
|
||||||
two:
|
two:
|
||||||
name: Ruby on Rails
|
name: Ruby on Rails
|
||||||
website: https://rubyonrails.org
|
website: https://rubyonrails.org
|
||||||
|
|
||||||
|
three:
|
||||||
|
name: Ruby
|
||||||
|
|
4
test/fixtures/versions.yml
vendored
4
test/fixtures/versions.yml
vendored
|
@ -3,9 +3,9 @@
|
||||||
one:
|
one:
|
||||||
number: 1.0.0
|
number: 1.0.0
|
||||||
date: 2018-07-22 20:30:46
|
date: 2018-07-22 20:30:46
|
||||||
software: two
|
branch: one
|
||||||
|
|
||||||
two:
|
two:
|
||||||
number: 1.1.0
|
number: 1.1.0
|
||||||
date: 2018-12-22 20:30:46
|
date: 2018-12-22 20:30:46
|
||||||
software: two
|
branch: two
|
||||||
|
|
7
test/models/branch_test.rb
Normal file
7
test/models/branch_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class BranchTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/github_repository_test.rb
Normal file
7
test/models/github_repository_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class GithubRepositoryTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/repository_github_test.rb
Normal file
7
test/models/repository_github_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class RepositoryGithubTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in a new issue