Skip to content
This repository

Added license information to versions. #458

Merged
merged 1 commit into from over 1 year ago

5 participants

Pivotal Labs Common Effort Role Account Mike Dalessio Amos King Vinny Diehl Matt Parker
Pivotal Labs Common Effort Role Account

The license is stored in the database upon creation of a new version. It is then made visible on the web and via the API. This addresses #363.

Existing gem versions will still need to have their license information backfilled, per #422.

Pivotal Labs Common Effort Role Account

Any thoughts on this? Would love to see this get merged.

Mike Dalessio flavorjones referenced this pull request in seattlerb/hoe September 14, 2012
Closed

Licenses #32

Mike Dalessio

+1 on this -- closing #363 will most definitely help enterprisey Rubyists.

Amos King
Collaborator

:+1:

It would be nice to see the license before I download it and find out I have to GPL my project.

pivotal-gemini pivotal-gemini referenced this pull request in fastestforward/heroku_san November 08, 2012
Closed

Add license to gemspec #107

Vinny Diehl

:+1:, I agree with @adkron.

app/models/version.rb
... ...
@@ -262,6 +264,10 @@ def join_authors
262 264
     self.authors = self.authors.join(', ') if self.authors.is_a?(Array)
263 265
   end
264 266
 
  267
+  def join_licenses
  268
+    self.licenses = self.licenses.join(', ') if self.licenses.is_a?(Array)
2
Amos King Collaborator
adkron added a note November 08, 2012

Let's check that it responds to join instead of checking if it is an array. :tada:

will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
app/views/rubygems/show.html.erb
((6 lines not shown))
55 55
               <h5><%= t '.owners_header' %></h5>
56 56
               <p><%= links_to_owners(@rubygem) %></p>
57 57
             </div>
58 58
           <% end %>
59 59
 
  60
+          <% if @latest_version.licenses.present? %>
3
Amos King Collaborator
adkron added a note November 08, 2012

Instead of checking that licenses are present lets just print them. If they are empty then they are empty. What do you think?

Amos King Collaborator
adkron added a note November 08, 2012

I've suggested this somewhere else, but what do you think about returning NA if their are no licenses?

Sounds great to me. On it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Display licenses for gem versions. b49db33
Matt Parker

hi @adkron I've updated the commit. Cheers.

Amos King adkron merged commit b0f23a1 into from November 16, 2012
Amos King adkron closed this November 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 2 authors.

Nov 15, 2012
Display licenses for gem versions. b49db33
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -18,3 +18,4 @@ pkg/
18 18
 server/
19 19
 tmp/
20 20
 tags
  21
+.idea
8  app/helpers/rubygems_helper.rb
... ...
@@ -1,4 +1,12 @@
1 1
 module RubygemsHelper
  2
+  def formatted_licenses(license_names)
  3
+    if license_names.blank?
  4
+      t(".no_licenses")
  5
+    else
  6
+      Array(license_names).join ", "
  7
+    end
  8
+  end
  9
+
2 10
   def link_to_page(text, url)
3 11
     link_to(text, url, :rel => 'nofollow') if url.present?
4 12
   end
4  app/models/version.rb
@@ -7,6 +7,8 @@ class Version < ActiveRecord::Base
7 7
   after_create     :full_nameify!
8 8
   after_save       :reorder_versions
9 9
 
  10
+  serialize :licenses
  11
+
10 12
   validates :number,   :format => {:with => /\A#{Gem::Version::VERSION_PATTERN}\z/}
11 13
   validates :platform, :format => {:with => Rubygem::NAME_PATTERN}
12 14
 
@@ -141,6 +143,7 @@ def update_attributes_from_gem_specification!(spec)
141 143
       :authors     => spec.authors,
142 144
       :description => spec.description,
143 145
       :summary     => spec.summary,
  146
+      :licenses    => spec.licenses,
144 147
       :built_at    => spec.date,
145 148
       :indexed     => true
146 149
     )
@@ -183,6 +186,7 @@ def payload
183 186
       'summary'         => summary,
184 187
       'platform'        => platform,
185 188
       'prerelease'      => prerelease,
  189
+      'licenses'        => licenses
186 190
     }
187 191
   end
188 192
 
8  app/views/rubygems/show.html.erb
@@ -31,7 +31,7 @@
31 31
 
32 32
       <% if @latest_version.indexed %>
33 33
         <div class="who">
34  
-          <div class="authors">
  34
+          <div class="authors info-item">
35 35
             <% if @latest_version.authors.present? %>
36 36
               <h5><%= t '.authors_header' %></h5>
37 37
               <p><%= @latest_version.authors %></p>
@@ -50,12 +50,16 @@
50 50
           <% end %>
51 51
 
52 52
           <% if @rubygem.owners.present? %>
53  
-            <div class="owners">
  53
+            <div class="owners info-item">
54 54
               <h5><%= t '.owners_header' %></h5>
55 55
               <p><%= links_to_owners(@rubygem) %></p>
56 56
             </div>
57 57
           <% end %>
58 58
 
  59
+          <div class="licenses info-item">
  60
+            <h5><%= t '.licenses_header' %></h5>
  61
+            <p><%= formatted_licenses @latest_version.licenses %></p>
  62
+          </div>
59 63
         </div>
60 64
 
61 65
         <% if @rubygem.linkset.present? %>
2  config/locales/en.yml
@@ -158,6 +158,8 @@ en:
158 158
       versions_header: Versions
159 159
       bundler_header: Gemfile
160 160
       show_all_versions: "Show all versions (%{count} total)"
  161
+      licenses_header: Licenses
  162
+      no_licenses: N/A
161 163
 
162 164
   searches:
163 165
     show:
5  db/migrate/20120904155203_add_license_to_versions.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AddLicenseToVersions < ActiveRecord::Migration
  2
+  def change
  3
+    add_column :versions, :licenses, :string
  4
+  end
  5
+end
1  db/schema.rb
@@ -143,6 +143,7 @@
143 143
     t.integer  "position"
144 144
     t.boolean  "latest"
145 145
     t.string   "full_name"
  146
+    t.string   "licenses"
146 147
   end
147 148
 
148 149
   add_index "versions", ["built_at"], :name => "index_versions_on_built_at"
13  features/gems_api.feature
@@ -5,15 +5,15 @@ Feature: List gems API
5 5
 
6 6
   Scenario: Anonymous user lists gems for owner
7 7
     Given the following user exists:
8  
-      | email            | handle     |
  8
+      | email            | handle   |
9 9
       | user@example.com | myhandle |
10 10
     And the following version exists:
11 11
       | rubygem    | number |
12  
-      | name: AGem | 1.0.0 |
  12
+      | name: AGem | 1.0.0  |
13 13
     And the following ownership exists:
14 14
       | rubygem    | user                    |
15 15
       | name: AGem | email: user@example.com |
16  
-      | name: BGem | |
  16
+      | name: BGem |                         |
17 17
     When I list the gems for owner "myhandle"
18 18
     Then I should see "AGem"
19 19
     And I should not see "BGem"
@@ -33,3 +33,10 @@ Feature: List gems API
33 33
       | name: MyGem | email: original@owner.org |
34 34
     When I list the gems with my API key
35 35
     Then I should see "MyGem"
  36
+
  37
+  Scenario: Gem versions include all gem version data
  38
+    Given the following version exists:
  39
+      | rubygem                  | number | licenses |
  40
+      | name: testgemwithlicense | 1.0.0  | MIT      |
  41
+    When I GET "/api/v1/versions/testgemwithlicense.json"
  42
+    Then the JSON response should include all of the gem version metadata
23  features/push.feature
@@ -3,14 +3,33 @@ Feature: Push Gems
3 3
   A rubygem developer
4 4
   Should be able to push gems up to Gemcutter
5 5
 
6  
-  Scenario: User pushes new gem
  6
+  Scenario: User pushes new gem and sees metadata
7 7
     Given I am signed up as "email@person.com"
8  
-    And I have a gem "RGem" with version "1.2.3"
  8
+    And I have a gem "RGem" with version "1.2.3" and the following attributes:
  9
+      | authors  | description  | license |
  10
+      | John Doe | The best gem | MIT     |
9 11
     And I have an API key for "email@person.com/password"
10 12
     When I push the gem "RGem-1.2.3.gem" with my API key
11 13
     And I visit the gem page for "RGem"
12 14
     Then I should see "RGem"
13 15
     And I should see "1.2.3"
  16
+    And I should see "John Doe"
  17
+    And I should see "The best gem"
  18
+    And I should see "MIT"
  19
+
  20
+  Scenario: User pushes new gem and sees metadata
  21
+    Given I am signed up as "email@person.com"
  22
+    And I have a gem "RGem" with version "1.2.3" and the following attributes:
  23
+      | authors  | description  |
  24
+      | John Doe | The best gem |
  25
+    And I have an API key for "email@person.com/password"
  26
+    When I push the gem "RGem-1.2.3.gem" with my API key
  27
+    And I visit the gem page for "RGem"
  28
+    Then I should see "RGem"
  29
+    And I should see "1.2.3"
  30
+    And I should see "John Doe"
  31
+    And I should see "The best gem"
  32
+    And I should see "N/A"
14 33
 
15 34
   Scenario: User pushes existing version of existing gem
16 35
     Given I am signed up as "email@person.com"
15  features/step_definitions/api_steps.rb
@@ -11,6 +11,20 @@
11 11
   page.driver.post api_v1_rubygems_path, File.read(path), {"CONTENT_TYPE" => "application/octet-stream"}
12 12
 end
13 13
 
  14
+When /^I GET "(.*?)"$/ do |url|
  15
+  get url
  16
+end
  17
+
  18
+Then /^the JSON response should include all of the gem version metadata$/ do
  19
+  response = JSON.parse last_response.body
  20
+
  21
+  version = Version.first
  22
+
  23
+  version.payload.each do |attribute, value|
  24
+    assert_equal value, response.first[attribute] unless attribute == "built_at"
  25
+  end
  26
+end
  27
+
14 28
 When /^I push the gem "([^\"]*)" with my API key$/ do |name|
15 29
   api_key_header
16 30
   path = File.join(TEST_DIR, name)
@@ -81,3 +95,4 @@
81 95
 Then /the response should contain "([^"]+)"/ do |text|
82 96
   assert_match text, page.source
83 97
 end
  98
+
8  features/step_definitions/gem_steps.rb
@@ -25,6 +25,14 @@
25 25
   build_gemspec(gemspec)
26 26
 end
27 27
 
  28
+Given /^I have a gem "([^\"]*)" with version "([^\"]*)" and the following attributes:$/ do |name, version, table|
  29
+  gemspec = new_gemspec(name, version, "Gemcutter", "ruby")
  30
+  table.hashes.first.each do |key, value|
  31
+    gemspec.send("#{key}=", value)
  32
+  end
  33
+  build_gemspec(gemspec)
  34
+end
  35
+
28 36
 Given /^I have a bad gem "([^\"]*)" with version "([^\"]*)"$/ do |name, version|
29 37
   gemspec = new_gemspec(name, version, "Bad Gem", "ruby")
30 38
   gemspec.name = eval(name)
1  features/support/gem_helper.rb
@@ -24,6 +24,7 @@ def new_gemspec(name, version, summary, platform)
24 24
       s.rubygems_version = %q{1.3.5}
25 25
       s.summary = "#{summary}"
26 26
       s.test_files = []
  27
+      s.licenses = []
27 28
     end
28 29
 
29 30
     def gemspec.validate
17  public/stylesheets/screen.css
@@ -641,19 +641,24 @@ table {
641 641
   border-bottom: 1px solid #B4AC99;
642 642
 }
643 643
 
644  
-.main .info .meta .authors {
645  
-  display: inline-block;
646  
-  width: 50%;
  644
+.main .info .meta .info-item {
  645
+  width: 100%;
  646
+  margin-top: 13px;
647 647
 }
648 648
 
649  
-.main .info .meta .owners h5 {
650  
-  margin-top: 13px;
  649
+.main .info .meta .info-item:first-child {
  650
+  margin-top: 0;
651 651
 }
652 652
 
653  
-.main .info .meta .owners p {
  653
+.main .info .meta .info-item p {
654 654
   width: 100%;
655 655
 }
656 656
 
  657
+.main .info .meta .authors {
  658
+  display: inline-block;
  659
+  width: 50%;
  660
+}
  661
+
657 662
 .main .info .meta .owners img {
658 663
   margin-right: 5px;
659 664
 }
1  test/factories.rb
@@ -80,6 +80,7 @@
80 80
     indexed true
81 81
     number
82 82
     platform "ruby"
  83
+    licenses "MIT"
83 84
     rubygem
84 85
   end
85 86
 
1  test/test_helper.rb
@@ -77,6 +77,7 @@ def gem_spec(opts = {})
77 77
     s.authors = ["Joe User"]
78 78
     s.description = %q{This is my awesome gem.}
79 79
     s.email = %q{joe@user.com}
  80
+    s.licenses = %w(MIT BSD)
80 81
     s.files = [
81 82
       "README.textile",
82 83
       "Rakefile",
16  test/unit/version_test.rb
@@ -11,7 +11,7 @@ class VersionTest < ActiveSupport::TestCase
11 11
 
12 12
     should "only have relevant API fields" do
13 13
       json = @version.as_json
14  
-      assert_equal %w[number built_at summary description authors platform prerelease downloads_count].map(&:to_s).sort, json.keys.sort
  14
+      assert_equal %w[number built_at summary description authors platform prerelease downloads_count licenses].map(&:to_s).sort, json.keys.sort
15 15
       assert_equal @version.authors, json["authors"]
16 16
       assert_equal @version.built_at, json["built_at"]
17 17
       assert_equal @version.description, json["description"]
@@ -20,6 +20,7 @@ class VersionTest < ActiveSupport::TestCase
20 20
       assert_equal @version.platform, json["platform"]
21 21
       assert_equal @version.prerelease, json["prerelease"]
22 22
       assert_equal @version.summary, json["summary"]
  23
+      assert_equal @version.licenses, json["licenses"]
23 24
     end
24 25
   end
25 26
 
@@ -30,7 +31,7 @@ class VersionTest < ActiveSupport::TestCase
30 31
 
31 32
     should "only have relevant API fields" do
32 33
       xml = Nokogiri.parse(@version.to_xml)
33  
-      assert_equal %w[number built-at summary description authors platform prerelease downloads-count].map(&:to_s).sort, xml.root.children.map{|a| a.name}.reject{|t| t == "text"}.sort
  34
+      assert_equal %w[number built-at summary description authors platform prerelease downloads-count licenses].map(&:to_s).sort, xml.root.children.map{|a| a.name}.reject{|t| t == "text"}.sort
34 35
       assert_equal @version.authors, xml.at_css("authors").content
35 36
       assert_equal @version.built_at.to_i, xml.at_css("built-at").content.to_time.to_i
36 37
       assert_equal @version.description, xml.at_css("description").content
@@ -39,6 +40,7 @@ class VersionTest < ActiveSupport::TestCase
39 40
       assert_equal @version.platform, xml.at_css("platform").content
40 41
       assert_equal @version.prerelease.to_s, xml.at_css("prerelease").content
41 42
       assert_equal @version.summary.to_s, xml.at_css("summary").content
  43
+      assert_equal @version.licenses, xml.at_css("licenses").content
42 44
     end
43 45
   end
44 46
 
@@ -459,7 +461,7 @@ class VersionTest < ActiveSupport::TestCase
459 461
 
460 462
   context "with a Gem::Specification" do
461 463
     setup do
462  
-      @spec    = gem_specification_from_gem_fixture('test-0.0.0')
  464
+      @spec    = gem_spec
463 465
       @version = build(:version)
464 466
     end
465 467
 
@@ -476,10 +478,10 @@ class VersionTest < ActiveSupport::TestCase
476 478
       @version.update_attributes_from_gem_specification!(@spec)
477 479
 
478 480
       assert @version.indexed
479  
-      assert_equal @spec.authors.join(', '), @version.authors
480  
-      assert_equal @spec.description,        @version.description
481  
-      assert_equal @spec.summary,            @version.summary
482  
-      assert_equal @spec.date,               @version.built_at
  481
+      assert_equal @spec.authors.join(', '),  @version.authors
  482
+      assert_equal @spec.description,         @version.description
  483
+      assert_equal @spec.summary,             @version.summary
  484
+      assert_equal @spec.date,                @version.built_at
483 485
     end
484 486
   end
485 487
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.