Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
feat: Add repository description (#490)
Browse files Browse the repository at this point in the history
* feat: allow description in repositories for admins to register

* feat: display repository description in index

---------

Co-authored-by: Alessandro Dias Batista <alessandro.dias@codeminer42.com>
  • Loading branch information
thiagofportella and Alessandro Dias Batista authored Jul 26, 2023
1 parent cd12170 commit d624d45
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
4 changes: 3 additions & 1 deletion app/admin/repositories.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ActiveAdmin.register Repository do
permit_params :link, :language, :highlight
permit_params :link, :language, :highlight, :description

filter :link
filter :language
Expand All @@ -17,6 +17,7 @@
form do |f|
f.inputs do
f.input :link
f.input :description
f.input :language
f.input :highlight
end
Expand All @@ -26,6 +27,7 @@
show do
attributes_table do
row :link
row :description
row :language
row :highlight
row :created_at
Expand Down
1 change: 1 addition & 0 deletions app/views/repositories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<i class="fab fa-github"></i>
<span class="d-inline-block"><%= repository.link %></span>
<span class="d-inline-block float-right"> <%= repository.languages %></span>
<span class="d-block text-dark"><%= simple_format repository.description %></span>
<% end %>
<% end %>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt-BR/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ pt-BR:
link: "Link"
name: "Nome"
language: "Linguagem"
description: "Descrição"
created_at: "Criado em"
updated_at: "Atualizado em"
contribution:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230724160449_add_description_to_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDescriptionToRepositories < ActiveRecord::Migration[7.0]
def change
add_column :repositories, :description, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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|
Expand Down
3 changes: 2 additions & 1 deletion spec/factories/repositories.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 9 additions & 4 deletions spec/features/admin/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions spec/features/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,65 @@
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

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

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

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)
Expand Down

0 comments on commit d624d45

Please sign in to comment.