Skip to content
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

Replaced organization github name and project repo fields with Project github url #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ GEM
hashie (2.0.3)
hike (1.2.3)
httpauth (0.2.0)
i18n (0.6.11)
i18n (0.7.0)
inherited_resources (1.4.0)
has_scope (~> 0.5.0)
responders (~> 0.9)
Expand All @@ -141,7 +141,7 @@ GEM
polyamorous (~> 0.5.0)
mime-types (1.25.1)
mini_portile (0.5.2)
multi_json (1.10.1)
multi_json (1.11.0)
multipart-post (1.2.0)
newrelic_rpm (3.9.0.229)
nokogiri (1.6.1)
Expand Down Expand Up @@ -222,7 +222,7 @@ GEM
sawyer (0.5.5)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
shoulda-matchers (2.0.0)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
simple_form (2.1.0)
actionpack (~> 3.0)
Expand Down
18 changes: 15 additions & 3 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
class Organization < ActiveRecord::Base
before_save :delete_logo
before_create :set_github_org

has_many :jobs
has_many :projects
has_many :organization_metrics
has_many :sponsorships

attr_accessible :name, :url, :github_org, :description, :is_tax_exempt, :contact_name, :contact_role, :contact_email, :annual_budget_usd, :total_staff_size, :tech_staff_size, :notes, :image_url, :twitter, :logo, :logo_delete
attr_accessible :name, :url, :github_org, :description,
:is_tax_exempt, :contact_name, :contact_role,
:contact_email, :annual_budget_usd, :total_staff_size,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

:tech_staff_size, :notes, :image_url, :twitter, :logo,
:logo_delete
attr_accessible :organization_metrics_attributes, :projects_attributes

attr_writer :logo_delete
attr_accessor :is_public_submission

validates_presence_of :name
validates_presence_of :github_org, if: :is_public_submission
validates :name, presence: true

# Paperclip
has_attached_file :logo, styles: { thumb: '100x100>', medium: '250x250>' },
Expand Down Expand Up @@ -48,4 +52,12 @@ def logo_delete
def delete_logo
logo.clear if logo_delete == '1'
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

def set_github_org
if projects.first
self.github_org = Project.parse_git_url(projects.first.submitted_github_url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

.split('/')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the previous line, together with the method call receiver.
Align the operands of an expression in an assignment spanning multiple lines.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the previous line, together with the method call receiver.
Use 2 (not 20) spaces for indenting an expression spanning multiple lines.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

.first

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the previous line, together with the method call receiver.
Align the operands of an expression in an assignment spanning multiple lines.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the previous line, together with the method call receiver.
Use 2 (not 20) spaces for indenting an expression spanning multiple lines.

end
end
end
24 changes: 22 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
class Project < ActiveRecord::Base
before_create :set_github_repo
belongs_to :organization
acts_as_ordered_taggable
acts_as_ordered_taggable_on :technologies, :causes

attr_accessible :cause_list, :description, :github_repo, :help_url,
:install_url, :is_active, :is_approved, :name, :notes,
:organization_id, :technology_list, :url, :twitter
validates_presence_of :name, :github_repo
:organization_id, :technology_list, :url, :twitter,
:submitted_github_url

attr_accessor :submitted_github_url
validates :name, presence: true
validates :github_repo, presence: true, on: :update
validates :submitted_github_url, presence: true,
format: { with: /\Ahttps?:\/\/github.com\/[\w-]+\/[\w\.-]+(\/)?\Z/i,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]
Align the elements of a hash literal if they span more than one line.
Trailing whitespace detected.

message: 'Please enter a valid GitHub URL.' },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

on: :create

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of a hash literal if they span more than one line.


has_many :favorite_projects
has_many :users, through: :favorite_projects
Expand Down Expand Up @@ -60,4 +69,15 @@ def related_projects
def tasks_url
"#{github_url}/issues"
end

def self.parse_git_url(url)
url.gsub(/^(((https|http|git)?:\/\/(www\.)?)|git@)github.com(:|\/)/i, '')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

.gsub(/(\.git|\/)$/i, '')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the previous line, together with the method call receiver.
Use 2 (not 3) spaces for indenting an expression spanning multiple lines.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

private

def set_github_repo
self.github_repo = Project.parse_git_url(submitted_github_url).split('/').last

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
end
7 changes: 3 additions & 4 deletions app/views/organizations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
<%= f.simple_fields_for :projects do |project| %>
<div class="row">
<%= project.input :name, :label => 'Project Name', wrapper_html: { class: "large-6 columns" }, error_html: { class: "error"} %>
<%= project.input :github_repo, :label => 'GitHub Repository', :placeholder => 'Just the repo name, please...', wrapper_html: { class: 'large-6 columns' }, error_html: { class: "error"} %>
<%= project.input :submitted_github_url, :label => 'GitHub Repository URL', :placeholder => 'Just the repo url, please...', wrapper_html: { class: 'large-6 columns' }, error_html: { class: "error"} %>
</div>
<%= project.input :url, :label => 'Project Website' %>
<%= project.input :description, :placeholder => 'What does your project do?' %>
<% end %>

<%= f.input :name, :label => 'Organization Name', error_html: { class: "error" } %>
<div class="row">
<%= f.input :github_org, :label => 'Organization GitHub Username', :required => true, wrapper_html: { class: 'large-6 columns'}, error_html: { class: "error"} %>
<%= f.input :name, :label => 'Organization Name', wrapper_html: { class: 'large-6 columns'}, error_html: { class: "error" } %>
<%= f.input :url, :label => 'Organization Website', :required => false, :as => :url, wrapper_html: { class: 'large-6 columns'} %>
</div>
<div class="row">
Expand All @@ -32,4 +31,4 @@

<p>Already a CodeMontage Organization? <%= mail_to "projects@codemontage.com", "Submit a New Project", :subject => "New project for my organization" %></p>

</body>
</body>
1 change: 1 addition & 0 deletions spec/factories/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
association :organization
name "CodeMontage"
github_repo "codemontage"
submitted_github_url "https://github.com/CodeMontageHQ/codemontage"
end
end
23 changes: 18 additions & 5 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
it { should validate_presence_of(:name) }

context 'validations' do
context 'if public submission' do
before { subject.stub(:is_public_submission) { true } }
it { should validate_presence_of(:github_org) }
end

context 'if not public submission' do
before { subject.stub(:is_public_submission) { false } }
it { should_not validate_presence_of(:github_org) }
Expand All @@ -21,6 +16,24 @@
end
end

context 'create organization' do
let(:organization) {
Organization.new(projects_attributes: { "0" =>
{
name: "sidekiq",
submitted_github_url: "https://github.com/mperham/sidekiq"
}
},
name: "Mperham")
}

it 'populates github_repo and github_org upon create' do
organization.save
expect(organization.projects.first.github_repo).to eq('sidekiq')
expect(organization.github_org).to eq('mperham')
end
end

context 'url wrangling' do
let(:organization) { Organization.new(url: 'http://www.amazing.org', github_org: 'amazing') }

Expand Down
13 changes: 10 additions & 3 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
it { should have_many(:events).through(:featured_projects) }

it { should validate_presence_of(:name) }
it { should validate_presence_of(:github_repo) }
it { should validate_presence_of(:submitted_github_url).on(:create) }
it { should validate_presence_of(:github_repo).on(:update) }

context 'github-related methods' do
let(:project) { Project.new }
Expand Down Expand Up @@ -86,12 +87,18 @@
let(:organization) { Organization.create!(name: 'CodeMontage') }

before do
@project_1 = Project.create!(name: 'Code Montage', organization_id: organization.id, github_repo: 'codemontage')
@project_2 = Project.create!(name: 'Happy Days', organization_id: organization.id, github_repo: 'happydays')
@project_1 = Project.create!(name: 'Code Montage', organization_id: organization.id, submitted_github_url: 'https://github.com/CodeMontageHQ/codemontage')
@project_2 = Project.create!(name: 'Happy Days', organization_id: organization.id, submitted_github_url: 'https://github.com/kig/happydays')
end

it "returns its organization's other projects" do
expect(@project_1.related_projects).to eq([@project_2])
end
end

describe '.parse_git_url' do
it "returns organization/repo given a github project url" do
expect(Project.parse_git_url('https://github.com/CodeMontageHQ/codemontage')).to eq('CodeMontageHQ/codemontage')
end
end
end