From d624d45c97441b707adfe3c6f61f019959968a0c Mon Sep 17 00:00:00 2001 From: Thiago Portella <52546576+thiagofportella@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:12:32 -0300 Subject: [PATCH] feat: Add repository description (#490) * feat: allow description in repositories for admins to register * feat: display repository description in index --------- Co-authored-by: Alessandro Dias Batista --- app/admin/repositories.rb | 4 +++- app/views/repositories/index.html.erb | 1 + config/locales/pt-BR/models.yml | 1 + ...4160449_add_description_to_repositories.rb | 5 ++++ db/schema.rb | 3 ++- spec/factories/repositories.rb | 3 ++- spec/features/admin/repositories_spec.rb | 13 ++++++---- spec/features/repositories_spec.rb | 24 +++++++++++-------- 8 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20230724160449_add_description_to_repositories.rb diff --git a/app/admin/repositories.rb b/app/admin/repositories.rb index b6b20285a..d0ad1ad58 100644 --- a/app/admin/repositories.rb +++ b/app/admin/repositories.rb @@ -1,5 +1,5 @@ ActiveAdmin.register Repository do - permit_params :link, :language, :highlight + permit_params :link, :language, :highlight, :description filter :link filter :language @@ -17,6 +17,7 @@ form do |f| f.inputs do f.input :link + f.input :description f.input :language f.input :highlight end @@ -26,6 +27,7 @@ show do attributes_table do row :link + row :description row :language row :highlight row :created_at diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb index e64989e2a..f28d14175 100644 --- a/app/views/repositories/index.html.erb +++ b/app/views/repositories/index.html.erb @@ -21,6 +21,7 @@ <%= repository.link %> <%= repository.languages %> + <%= simple_format repository.description %> <% end %> <% end %> diff --git a/config/locales/pt-BR/models.yml b/config/locales/pt-BR/models.yml index 9efafbdfc..9a47e31ce 100644 --- a/config/locales/pt-BR/models.yml +++ b/config/locales/pt-BR/models.yml @@ -334,6 +334,7 @@ pt-BR: link: "Link" name: "Nome" language: "Linguagem" + description: "Descrição" created_at: "Criado em" updated_at: "Atualizado em" contribution: diff --git a/db/migrate/20230724160449_add_description_to_repositories.rb b/db/migrate/20230724160449_add_description_to_repositories.rb new file mode 100644 index 000000000..ea3bd4b31 --- /dev/null +++ b/db/migrate/20230724160449_add_description_to_repositories.rb @@ -0,0 +1,5 @@ +class AddDescriptionToRepositories < ActiveRecord::Migration[7.0] + def change + add_column :repositories, :description, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 882976502..7704de159 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_07_14_130703) do +ActiveRecord::Schema[7.0].define(version: 2023_07_24_160449) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -188,6 +188,7 @@ t.datetime "updated_at", precision: nil, null: false t.string "language" t.boolean "highlight", default: false + t.text "description" end create_table "skills", force: :cascade do |t| diff --git a/spec/factories/repositories.rb b/spec/factories/repositories.rb index 9c3ae788c..83ed9125d 100644 --- a/spec/factories/repositories.rb +++ b/spec/factories/repositories.rb @@ -1,8 +1,9 @@ FactoryBot.define do factory :repository do - sequence :link do |n| + sequence :link do |n| "https://github.com/Codeminer42/project-#{Faker::Number.number(digits: 2)}#{n}" end language { Faker::ProgrammingLanguage.name } + description { Faker::Movies::HarryPotter.quote } end end diff --git a/spec/features/admin/repositories_spec.rb b/spec/features/admin/repositories_spec.rb index c6fc83122..209ced1bf 100644 --- a/spec/features/admin/repositories_spec.rb +++ b/spec/features/admin/repositories_spec.rb @@ -14,7 +14,7 @@ describe 'Index' do it 'must find fields "Link" on table' do within 'table' do - expect(page).to have_text('Link') & + expect(page).to have_text('Link') & have_text('Linguagem') end end @@ -40,12 +40,14 @@ expect(page).to have_text('Link') & have_text('Linguagem') & have_text('Criado em') & + have_text('Descrição') & have_text('Atualizado em') end it 'have repository table with correct information' do expect(page).to have_text(repository.link) & have_text(repository.language) & + have_text(repository.description) & have_text(I18n.l(repository.created_at, format: :long)) & have_text(I18n.l(repository.updated_at, format: :long)) end @@ -61,11 +63,13 @@ it 'must have the form working' do fill_in 'Link', with: 'https://github.com/example' fill_in 'Linguagem', with: 'Ruby on Rails' + fill_in 'Descrição', with: 'Web-application framework' click_button 'Criar Repositório' expect(page).to have_css('.flash_notice', text: 'Repositório foi criado com sucesso.') & have_text('Ruby on Rails') & - have_text('https://github.com/example') + have_text('https://github.com/example') & + have_text('Web-application framework') end end @@ -78,7 +82,8 @@ it 'must have labels' do within 'form' do expect(page).to have_text('Link') & - have_text('Linguagem') + have_text('Linguagem') & + have_text('Descrição') end end @@ -90,7 +95,7 @@ expect(page).to have_css('.flash_notice', text: 'Repositório foi atualizado com sucesso.') & have_text('https://github.com/new_link') & - have_text('Javascript') + have_text('Javascript') end end end diff --git a/spec/features/repositories_spec.rb b/spec/features/repositories_spec.rb index 20bf80880..9a094cf6d 100644 --- a/spec/features/repositories_spec.rb +++ b/spec/features/repositories_spec.rb @@ -4,37 +4,41 @@ let!(:authed_user) { create_logged_in_user } context 'without filter' do - let!(:repository) { create(:repository).decorate } let!(:second_repository) { create(:repository).decorate } - + before do visit repositories_path end - + it 'has the right count of 25 repositories' do create_list(:repository, 26) - + visit repositories_path expect(page).to have_css('.list-group .list-group-item', :count => 25) end - + it 'have all links for repositories' do expect(page).to have_link(repository.link, href: repository.link) & have_link(second_repository.link, href: second_repository.link) end - + it 'have all languages for repositories' do expect(page).to have_text(repository.languages) & have_text(second_repository.languages) end + + it 'has all descriptions for repositories' do + expect(page).to have_text(repository.description) & + have_text(second_repository.description) + end end context 'when filtering by languages' do let!(:repository) { create(:repository, language: 'javascript,ruby,python').decorate } let!(:second_repository) { create(:repository, language: 'Shell,react,python').decorate } - + before do visit repositories_path end @@ -42,7 +46,7 @@ it 'have the language javascript' do fill_in 'search-input-field', with: 'javascript' find('#filter-button').click - + expect(page).to have_text(repository.languages) expect(page).not_to have_text(second_repository.languages) end @@ -50,7 +54,7 @@ it 'not have any repository with Go' do fill_in 'search-input-field', with: 'go' find('#filter-button').click - + expect(page).not_to have_text(repository.languages) expect(page).not_to have_text(second_repository.languages) end @@ -58,7 +62,7 @@ it 'have two repositories with python' do fill_in 'search-input-field', with: 'python' find('#filter-button').click - + expect(page).to have_text(repository.languages) & have_text(second_repository.languages) expect(page).to have_css('.list-group .list-group-item', :count => 2)