From d2b621ddd61388ef1b528dbed6d0ad9e9962285c Mon Sep 17 00:00:00 2001
From: Adrien Waksberg
<%= form.text_field :website, class: 'uk-input' %>
+ <%= form.label :repository_type, class: 'uk-form-label' %>
+ <%= form.select :repository_type, %w[Github], {}, class: 'uk-select' %>
+
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
<% end %> + +<% case @software.repository_type %> +<% when 'Github' %> +
+ <%= form.label :repository, class: 'uk-form-label' %>
+ <%= form.text_field :name, value: @repository.name, class: 'uk-input' %>
+
+ <%= form.hidden_field :software_id, value: @software.id %> + <%= form.submit class: 'uk-button uk-button-default uk-margin' %> +
+<% end %> +<% end %> diff --git a/app/views/softwares/new.html.erb b/app/views/softwares/new.html.erb index 7dc27b1..ce6966f 100644 --- a/app/views/softwares/new.html.erb +++ b/app/views/softwares/new.html.erb @@ -18,6 +18,10 @@ <%= form.label :website, class: 'uk-form-label' %>
+ <%= form.label :repository_type, class: 'uk-form-label' %>
+ <%= form.select :repository_type, %w[Github], {}, class: 'uk-select' %>
+
<%= form.submit class: 'uk-button uk-button-default uk-margin' %>
diff --git a/config/routes.rb b/config/routes.rb index 8b80cab..bdc2b3f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do root 'home#index' - resources :softwares + resources :softwares do + resources :github_repository + end end diff --git a/db/migrate/20180729143537_add_column_repository_type_in_software.rb b/db/migrate/20180729143537_add_column_repository_type_in_software.rb new file mode 100644 index 0000000..15d07bd --- /dev/null +++ b/db/migrate/20180729143537_add_column_repository_type_in_software.rb @@ -0,0 +1,7 @@ +class AddColumnRepositoryTypeInSoftware < ActiveRecord::Migration[5.2] + def change + change_table :softwares do |t| + t.string :repository_type + end + end +end diff --git a/db/migrate/20180729191829_create_github_repositories.rb b/db/migrate/20180729191829_create_github_repositories.rb new file mode 100644 index 0000000..3173274 --- /dev/null +++ b/db/migrate/20180729191829_create_github_repositories.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 1364314..16c8fe4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,13 +10,22 @@ # # 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_07_29_191829) do + + 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| t.string "name", null: false t.string "website" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "repository_type" end create_table "versions", force: :cascade do |t| diff --git a/test/controllers/github_repository_controller_test.rb b/test/controllers/github_repository_controller_test.rb new file mode 100644 index 0000000..7384465 --- /dev/null +++ b/test/controllers/github_repository_controller_test.rb @@ -0,0 +1,45 @@ +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 with the same name exist' 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 +end diff --git a/test/fixtures/github_repositories.yml b/test/fixtures/github_repositories.yml new file mode 100644 index 0000000..f420338 --- /dev/null +++ b/test/fixtures/github_repositories.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: rails/rails + software: two diff --git a/test/models/github_repository_test.rb b/test/models/github_repository_test.rb new file mode 100644 index 0000000..b53630b --- /dev/null +++ b/test/models/github_repository_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class GithubRepositoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/repository_github_test.rb b/test/models/repository_github_test.rb new file mode 100644 index 0000000..e72c860 --- /dev/null +++ b/test/models/repository_github_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RepositoryGithubTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end