Skip to content

Feature/group offers #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ html {
margin: 14px 0;
padding: 5px 20px;

.post__group_label {
margin-left: 10px;
}

h4 {
font-weight: bold;
display: block;
Expand Down Expand Up @@ -710,3 +714,9 @@ label[required]::after{
line-height: 1.6em;
}
}

.inline-checkbox {
vertical-align: middle;
display: inline;
margin: 0 !important;
}
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set_user_id(p)

def post_params
permitted_fields = [:description, :end_on, :global, :joinable, :permanent,
:start_on, :title, :category_id, :user_id,
:start_on, :title, :category_id, :user_id, :is_group,
:publisher_id, :active, tag_list: []]

params.fetch(resource, {}).permit(*permitted_fields).tap do |p|
Expand Down
3 changes: 3 additions & 0 deletions app/views/shared/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<div class="panel-heading">
<h3 class="panel-title">
<%= post.class.model_name.human %>
<% if post.is_group %>
<div class="pull-right label label-default"><%= I18n.t("activerecord.attributes.#{post.class.name.downcase}.is_group") %></div>
<% end %>
</h3>
</div>
<div class="panel-body">
Expand Down
4 changes: 4 additions & 0 deletions app/views/shared/_post_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
{ include_blank: true },
class: "form-control" %>
</div>
<div class="form-group">
<%= label :post, :is_group, I18n.t("shared.post_form.group_#{post.class.name.downcase}"), required: true %>
<%= f.check_box :is_group, class: 'inline-checkbox' %>
</div>
<div class="form-group">
<%= f.label :tag_list %>
<%= f.select :tag_list,
Expand Down
3 changes: 3 additions & 0 deletions app/views/shared/_posts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<div class="post">
<h4>
<%= link_to post.title, post %>
<% if post.is_group %>
<div class="post__group_label label label-default"><%= I18n.t("activerecord.attributes.#{post.class.name.downcase}.is_group") %></div>
<% end %>
</h4>
<p>
<%= strip_tags(post.rendered_description.to_html) %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ en:
reg_number_seq: User sequence number
theme: Theme
updated_at: Updated
offer:
is_group: Group offer
inquiry:
is_group: Group inquiry
post:
category: Category
created_at: Created
Expand Down Expand Up @@ -419,6 +423,8 @@ en:
delete_reason: Are you sure to delete this comment?
movements: Movements
post_form:
group_offer: Is it a group offer?
group_inquiry: Is it a group inquiry?
you_can_use: You can use
simple_form:
error_notification:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190319121401_add_is_group_to_post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIsGroupToPost < ActiveRecord::Migration
def change
add_column :posts, :is_group, :boolean, default: false
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181004200104) do
ActiveRecord::Schema.define(version: 20190319121401) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -146,10 +146,11 @@
t.boolean "global"
t.datetime "created_at"
t.datetime "updated_at"
t.text "tags", array: true
t.text "tags", array: true
t.integer "publisher_id"
t.integer "organization_id"
t.boolean "active", default: true
t.boolean "is_group", default: false
end

add_index "posts", ["category_id"], name: "index_posts_on_category_id", using: :btree
Expand Down
37 changes: 37 additions & 0 deletions spec/views/inquiries/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

RSpec.describe 'inquiries/show' do
let(:organization) { Fabricate(:organization) }
let(:member) { Fabricate(:member, organization: organization) }
let(:inquiry) { Fabricate(:inquiry, user: member.user, organization: organization) }
let(:group_inquiry) { Fabricate(:inquiry, user: member.user, organization: organization, is_group: true) }
let(:destination_account) { Fabricate(:account) }


context 'when the user is not logged in' do
before do
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:current_organization).and_return(nil)
end

context 'when it is not a group inquiry' do
it 'displays a label' do
assign :inquiry, inquiry
assign :destination_account, destination_account
render template: 'inquiries/show'

expect(rendered).to_not include(I18n.t('activerecord.attributes.inquiry.is_group'))
end
end

context 'when it is a group inquiry' do
it 'displays a label' do
assign :inquiry, group_inquiry
assign :destination_account, destination_account
render template: 'inquiries/show'

expect(rendered).to include(I18n.t('activerecord.attributes.inquiry.is_group'))
end
end
end
end
21 changes: 21 additions & 0 deletions spec/views/offers/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let(:organization) { Fabricate(:organization) }
let(:member) { Fabricate(:member, organization: organization) }
let(:offer) { Fabricate(:offer, user: member.user, organization: organization) }
let(:group_offer) { Fabricate(:offer, user: member.user, organization: organization, is_group: true) }
let(:destination_account) { Fabricate(:account) }

before do
Expand Down Expand Up @@ -152,5 +153,25 @@

expect(rendered).to_not include(offer.user.email)
end

context 'when it is not a group offer' do
it 'displays a label' do
assign :offer, offer
assign :destination_account, destination_account
render template: 'offers/show'

expect(rendered).to_not include(I18n.t('activerecord.attributes.offer.is_group'))
end
end

context 'when it is a group offer' do
it 'displays a label' do
assign :offer, group_offer
assign :destination_account, destination_account
render template: 'offers/show'

expect(rendered).to include(I18n.t('activerecord.attributes.offer.is_group'))
end
end
end
end