Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved to lib -> ns -> function through rels. Fixed failing tests.

  • Loading branch information...
commit 7ff50be8656d6f35bd7c8b37f5bc5377b0400751 1 parent 2a00616
@zk authored
Showing with 206 additions and 174 deletions.
  1. +3 −0  Gemfile
  2. +8 −0 Gemfile.lock
  3. +16 −13 app/controllers/application_controller.rb
  4. +17 −31 app/controllers/main_controller.rb
  5. +4 −3 app/controllers/see_also_controller.rb
  6. +14 −20 app/models/function.rb
  7. +2 −1  app/models/library.rb
  8. +6 −0 app/models/namespace.rb
  9. +1 −1  app/views/_lib_namespaces.html.erb
  10. +7 −3 app/views/_missing_examples.html.erb
  11. +3 −3 app/views/_recently_updated.html.erb
  12. +1 −1  app/views/examples/view_changes.html.erb
  13. +3 −3 app/views/feed/recent_updates.rxml
  14. +15 −15 app/views/main/function.html.erb
  15. +7 −1 app/views/main/lib.html.erb
  16. +7 −10 app/views/main/ns.html.erb
  17. +3 −3 app/views/see_also/_see_also_content.html.erb
  18. +1 −0  config/database.example.yml
  19. +45 −0 db/migrate/20101010021829_add_lib_ns_var_rels.rb
  20. +9 −0 db/migrate/20101010034343_remove_lib_ns_from_var.rb
  21. +4 −4 db/schema.rb
  22. +8 −8 test/fixtures/functions.yml
  23. +4 −0 test/fixtures/libraries.yml
  24. +6 −0 test/fixtures/namespaces.yml
  25. +0 −8 test/functional/application_controller_test.rb
  26. +9 −13 test/functional/main_controller_test.rb
  27. +0 −30 test/unit/function_test.rb
  28. +3 −3 test/unit/helpers/appication_helper_test.rb
View
3  Gemfile
@@ -15,5 +15,8 @@ gem 'levenshtein', '0.2.0'
group :test do
gem "shoulda", "2.11.3"
gem "flexmock", "0.8.7"
+ gem "ZenTest", "4.4.0"
+ gem "autotest-fsevent", "0.2.3"
+ gem "autotest-growl", "0.2.6"
gem "rcov", "0.9.9", :require => nil
end
View
8 Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ ZenTest (4.4.0)
actionmailer (2.3.5)
actionpack (= 2.3.5)
actionpack (2.3.5)
@@ -11,6 +12,9 @@ GEM
activeresource (2.3.5)
activesupport (= 2.3.5)
activesupport (2.3.5)
+ autotest-fsevent (0.2.3)
+ sys-uname
+ autotest-growl (0.2.6)
chronic (0.2.3)
hoe (>= 1.2.1)
flexmock (0.8.7)
@@ -39,12 +43,16 @@ GEM
json_pure (>= 1.1.7)
rubytree (0.7.0)
shoulda (2.11.3)
+ sys-uname (0.8.4)
will_paginate (2.3.12)
PLATFORMS
ruby
DEPENDENCIES
+ ZenTest (= 4.4.0)
+ autotest-fsevent (= 0.2.3)
+ autotest-growl (= 0.2.6)
chronic (= 0.2.3)
flexmock (= 0.8.7)
levenshtein (= 0.2.0)
View
29 app/controllers/application_controller.rb
@@ -42,21 +42,24 @@ def find_recently_updated(size, lib = nil)
examples = Example.find(:all, :limit => size, :order => 'updated_at DESC')
see_alsos = SeeAlso.find(:all, :limit => size, :order => 'updated_at DESC')
else
- comments = Comment.find(:all,
- :joins => "INNER JOIN functions ON comments.commentable_id = functions.id",
- :conditions => ["functions.library = ?", lib],
- :limit => size,
- :order => 'updated_at DESC')
- examples = Example.find(:all,
- :joins => "INNER JOIN functions ON examples.function_id = functions.id",
- :conditions => ["functions.library = ?", lib],
- :limit => size,
- :order => 'updated_at DESC')
- see_alsos = SeeAlso.find(:all,
- :joins => "INNER JOIN functions ON see_alsos.from_id = functions.id",
- :conditions => ["functions.library = ?", lib],
+
+ comments = Comment.find(:all,
+ :joins => "INNER JOIN functions ON comments.commentable_id = functions.id LEFT JOIN namespaces ON functions.namespace_id = namespaces.id LEFT JOIN libraries ON namespaces.library_id = libraries.id",
+ :conditions => ["libraries.name = ?", lib],
:limit => size,
:order => 'updated_at DESC')
+
+ examples = Example.find(:all,
+ :include => [:function, {:function => :namespace}, {:function => {:namespace => :library}}],
+ :conditions => {:functions => {:namespaces => {:libraries => {:name => lib}}}},
+ :limit => size,
+ :order => 'examples.updated_at DESC')
+
+ see_alsos = SeeAlso.find(:all,
+ :include => [:from_function, {:from_function => :namespace}, {:from_function => {:namespace => :library}}],
+ :conditions => {:from_functions => {:namespaces => {:libraries => {:name => lib}}}},
+ :limit => size,
+ :order => 'see_alsos.updated_at DESC')
end
recent = (comments + examples + see_alsos).sort{|a,b| b.updated_at <=> a.updated_at}
View
48 app/controllers/main_controller.rb
@@ -146,14 +146,11 @@ def ns
@library = Library.find_by_url_friendly_name_and_current(lib_name, true)
end
- @ns = nil
- if version
- @ns = Namespace.find_by_name_and_version(ns_name, version)
- else
- @ns = Namespace.find_by_name(ns_name)
+ @ns = nil
+ if @library
+ @ns = Namespace.find_by_name_and_library_id(ns_name, @library.id)
end
-
if not @ns or not @library
render :template => 'public/404.html', :layout => false, :status => 404
return
@@ -167,23 +164,14 @@ def function
ns = params[:ns]
function_url_name = params[:function]
- @library = nil
- if version
- @library = Library.find_by_url_friendly_name_and_version(lib_url_name, version)
- else
- @library = Library.find_by_url_friendly_name_and_current(lib_url_name, true)
- end
-
- @ns = Namespace.find_by_name(ns)
@function = Function.find(
- :first,
+ :first,
+ :include => [:namespace, {:namespace => :library}],
:conditions => {
- :library => @library.name,
- :version => @library.version,
- :ns => ns,
+ :namespaces => {:name => ns, :libraries => {:url_friendly_name => lib_url_name}},
:url_friendly_name => function_url_name}
)
-
+
if not @function
logger.error "Couldn't find function id #{params[:id]}"
@@ -191,18 +179,10 @@ def function
return
end
- if not @library
- logger.error "Couldn't find library by function #{@function.to_yaml}"
-
- render :template => 'public/404.html', :layout => false, :status => 404
- return
- end
-
@example = Example.new
@comment = Comment.new
if request.post?
-
if params[:update_comment]
@comment = Comment.find(params[:comment_id])
if @comment and @comment.user_id == current_user.id
@@ -225,7 +205,13 @@ def function
def function_short_link
@function = Function.find(params[:id]) rescue nil
- @library = Library.find_by_name_and_version(@function.library, @function.version)
+
+ if not @function
+ logger.error "Couldn't find function id #{params[:id]}"
+
+ render :template => 'public/404.html', :layout => false, :status => 404
+ return
+ end
version = (params[:version] || @function.version)
@@ -238,9 +224,9 @@ def function_short_link
redirect_to :controller => 'main',
:action => 'function',
- :lib => @library.url_friendly_name,
- :version => (@library.current ? nil : @library.version),
- :ns => @function.ns,
+ :lib => @function.namespace.library.url_friendly_name,
+ :version => (@function.namespace.library.current ? nil : @function.namespace.library.version),
+ :ns => @function.namespace.name,
:function => @function.url_friendly_name
end
View
7 app/controllers/see_also_controller.rb
@@ -57,7 +57,7 @@ def lookup
@functions = @functions[0, 10]
end
- render :json => @functions.map{|f| {:href => f.href, :ns => f.ns, :name => f.name, :examples => f.examples.size, :shortdoc => f.shortdoc }}
+ render :json => @functions.map{|f| {:href => f.href, :ns => f.namespace.name, :name => f.name, :examples => f.examples.size, :shortdoc => f.shortdoc }}
end
def delete
@@ -112,7 +112,8 @@ def add
ns = split[0]
name = split[1]
- to_var = Function.find_by_ns_and_name(ns, name)
+ to_var = Function.find(:first, :include => [:namespace],
+ :conditions => {:namespaces => {:name => ns}, :name => name})
if not to_var
render json_fail("Couldn't find to var.")
@@ -136,7 +137,7 @@ def add
:to_var => {
:sa_id => sa.id,
:name => to_var.name,
- :ns => to_var.ns,
+ :ns => to_var.namespace.name,
:href => to_var.href,
:shortdoc => to_var.shortdoc
},
View
34 app/models/function.rb
@@ -1,4 +1,6 @@
class Function < ActiveRecord::Base
+ belongs_to :namespace
+
has_many :examples
has_many :comments
has_and_belongs_to_many :source_references,
@@ -43,6 +45,10 @@ def href
"/v/#{id}"
end
+ def library
+ namespace.library
+ end
+
def see_alsos_sorted
see_alsos.sort{|a,b| b.vote_score <=> a.vote_score}
end
@@ -51,32 +57,20 @@ def self.libraries
Function.find(:all, :select => 'distinct(library),library').map(&:library).sort
end
- def self.in_library(lib)
- Function.find(:all, :conditions => {:library => lib.name, :version => lib.version}, :select => 'library,ns,name, weight, id', :order => 'name ASC, weight DESC')
- end
-
- def self.in_library_and_ns(lib, ns)
- Function.find(:all, :conditions => {:library => lib.name, :ns => ns, :version => lib.version}, :order => 'name ASC, weight DESC')
- end
-
def self.versions_of(function)
- Function.find(:all, :conditions => {:library => function.library_.name,
- :ns => function.ns,
- :name => function.name})
- end
-
- # not ready to make the leap to a has_many / belongs_to yet, so this
- # will have to do for now
- def library_
- Library.find_by_name_and_version(library, version)
+ Function.find(:all,
+ :include => [:namespace, {:namespace => :library}],
+ :conditions => {:namespaces => {:name => function.namespace.name,
+ :libraries => {:name => function.library.name}},
+ :name => function.name})
end
def link_opts(use_current_vs_actual_version = true)
{:controller => 'main',
:action => 'function',
- :lib => library_.url_friendly_name,
- :version => (use_current_vs_actual_version && library_.current ? nil : version),
- :ns => ns,
+ :lib => library.url_friendly_name,
+ :version => (use_current_vs_actual_version && library.current ? nil : version),
+ :ns => namespace.name,
:function => url_friendly_name}
end
View
3  app/models/library.rb
@@ -1,6 +1,7 @@
class Library < ActiveRecord::Base
+
has_many :namespaces
-
+
#:nocov:
define_index do
indexes :name
View
6 app/models/namespace.rb
@@ -1,3 +1,9 @@
class Namespace < ActiveRecord::Base
belongs_to :library
+ has_many :functions
+
+ def self.versions_of(ns)
+ Namespace.find(:all, :conditions => {:name => ns.name})
+ end
+
end
View
2  app/views/_lib_namespaces.html.erb
@@ -9,7 +9,7 @@ current_ns = params[:ns]
if @library
require 'tree'
- _nss = Function.find(:all, :conditions => {:library => @library.name}, :select => 'distinct(ns),ns').map(&:ns).sort
+ _nss = @library.namespaces.map(&:name).sort
@ns_flat_list = _nss
View
10 app/views/_missing_examples.html.erb
@@ -1,6 +1,10 @@
<%
-total_count = Function.find_by_sql(["select count(id) from functions where library = ?", @lib.name])[0]["count(id)"].to_i
-missing_examples = Function.find_by_sql(["select distinct id, library, ns, name from functions where (id) not in (select function_id from examples) and library = ? order by name", @lib.name])
+#total_count = Function.find_by_sql(["select count(id) from functions where library = ?", @lib.name])[0]["count(id)"].to_i
+total_count = Function.count(:all,
+ :include => [:namespace, {:namespace => :library}],
+ :conditions => {:namespaces => {:libraries => {:name => @lib.name}}})
+
+missing_examples = Function.find_by_sql(["select distinct name, id from functions where (id) not in (select function_id from examples) order by name"])
missing_examples_count = missing_examples.size
functions_with_examples_count = total_count - missing_examples_count
@@ -30,7 +34,7 @@ groups = functions_group_into_alpha(missing_examples)
<h5><a name="missing_examples_<%= gs[0] %>"><%= gs[0] %></a></h5>
<ul>
<% gs[1].each do |f| %>
- <li><a href="<%= f.href %>"><span class="ns"><%= f.ns %>/</span><%= f.name %></a></li>
+ <li><a href="<%= f.href %>"><%= f.name %></a></li>
<% end %>
</ul>
<% end %>
View
6 app/views/_recently_updated.html.erb
@@ -8,7 +8,7 @@ recently_updated.each do |u|
<%= link_to u.user.login, :controller => 'user', :action => 'profile', :login => u.user.login %>
</span>
<%= (u.created_at == u.updated_at) ? "commented on" : "updated a comment on" %>
- <a href="<%= func.href %>"><span class="ns"><%= func.ns %>/</span><span class="name"><%= func.name %></span></a>
+ <a href="<%= func.href %>"><span class="ns"><%= func.namespace.name %>/</span><span class="name"><%= func.name %></span></a>
<%= time_ago_or_time_stamp(u.updated_at) %>
</div>
@@ -20,7 +20,7 @@ recently_updated.each do |u|
<%= link_to u.user.login, :controller => 'user', :action => 'profile', :login => u.user.login %>
</span>
<%= (u.created_at == u.updated_at) ? "added an example to" : "updated an example on" %>
- <a href="<%= func.href %>"><span class="ns"><%= func.ns %>/</span><span class="name"><%= func.name %></span></a>
+ <a href="<%= func.href %>"><span class="ns"><%= func.namespace.name %>/</span><span class="name"><%= func.name %></span></a>
<%= time_ago_or_time_stamp(u.updated_at)%>
</div>
@@ -32,7 +32,7 @@ recently_updated.each do |u|
<%= link_to u.user.login, :controller => 'user', :action => 'profile', :login => u.user.login %>
</span>
<%= (u.created_at == u.updated_at) ? "added a see also to" : "updated a see also on" %>
- <a href="<%= func.href %>"><span class="ns"><%= func.ns %>/</span><span class="name"><%= func.name %></span></a>
+ <a href="<%= func.href %>"><span class="ns"><%= func.namespace.name %>/</span><span class="name"><%= func.name %></span></a>
<%= time_ago_or_time_stamp(u.updated_at)%>
</div>
<% end %>
View
2  app/views/examples/view_changes.html.erb
@@ -1,7 +1,7 @@
<script type="text/javascript" charset="utf-8">
SyntaxHighlighter.all()
</script>
-<h1>Changes for <span class="ns"><%= @example.function.ns %>/</span><%= @example.function.name %></h1>
+<h1>Changes for <span class="ns"><%= @example.function.namespace.name %>/</span><%= @example.function.name %></h1>
<% @versions.each do |v| %>
<% if v.user_id
View
6 app/views/feed/recent_updates.rxml
@@ -22,15 +22,15 @@ xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
if r.instance_of? Comment
f = Function.find(r.commentable_id)
- title = "#{new_or_updated} comment on #{f.ns}/#{f.name} by #{author}."
+ title = "#{new_or_updated} comment on #{f.namespace.name}/#{f.name} by #{author}."
body = r.body
elsif r.instance_of? Example
f = r.function
- title = "#{new_or_updated} example for #{f.ns}/#{f.name} by #{author}."
+ title = "#{new_or_updated} example for #{f.namespace.name}/#{f.name} by #{author}."
body = r.body
elsif r.instance_of? SeeAlso
f = r.from_function
- title = "New see also for #{f.ns}/#{f.name} by #{author}."
+ title = "New see also for #{f.namespace.name}/#{f.name} by #{author}."
end
link = "http://clojuredocs.org#{f.href}"
View
30 app/views/main/function.html.erb
@@ -1,5 +1,5 @@
-<% content_for :title, " - #{@function.ns}/#{@function.name}" %>
+<% content_for :title, " - #{@function.namespace.name}/#{@function.name}" %>
<script type="text/javascript" charset="utf-8">
@@ -7,19 +7,19 @@
$(document).ready(function() {
CD.VarPage.init({
varId: <%= @function.id %>,
- library: "<%= @function.library %>",
+ library: "<%= @function.library.name %>",
editExampleFormHTML: '<%= (render :partial => '/examples/edit_example_form').gsub("\n", "")%>',
editCommentFormHTML: '<%= (render :partial => '/comments/edit_comment_form').gsub("\n", "")%>',
})
})
</script>
<div class="grid_3">
- <%= render :partial => 'lib_nav', :locals => {:lib => @library} %>
+ <%= render :partial => 'lib_nav', :locals => {:lib => @function.namespace.library} %>
<%= render :partial => '/lib_namespaces' %>
&nbsp;
</div>
<div class="grid_11">
- <% if not @function.library_.current %>
+ <% if not @function.library.current %>
<div class="version_warning">
You're viewing version <%= @function.version %> of <%= @function.name %>.
The latest stable version of <%= @library.name %> is <%= Library.current_version_of(@library).version %>.
@@ -45,7 +45,7 @@ $(document).ready(function() {
<div class="versions_nav">
<span>
<%= @function.version %>
- <% if @function.library_.current && params[:version] %>
+ <% if @function.library.current && params[:version] %>
permalink
<% end %>
<%= image_tag "arrow_down_16x16.png" %>
@@ -60,13 +60,13 @@ $(document).ready(function() {
<%
classes = []
if @function.version == f.version then classes << "selected" end
- if f.library_.current then classes << "stable" end
+ if f.library.current then classes << "stable" end
%>
<li>
- <% if @function.version == f.version && f.library_.current && !params[:version]%>
- <%= link_to f.version + " permalink", f.link_opts(false), :class => classes.join(' ') %>
+ <% if @function.library.version == f.library.version && f.library.current && !params[:version]%>
+ <%= link_to f.library.version + " permalink", f.link_opts(false), :class => classes.join(' ') %>
<% else %>
- <%= link_to f.version, f.link_opts, :class => classes.join(' ') %>
+ <%= link_to f.library.version, f.link_opts, :class => classes.join(' ') %>
<% end %>
</li>
<% end %>
@@ -80,11 +80,11 @@ $(document).ready(function() {
</h1>
<h2>
<span class="ns">
- <%= link_to @function.ns, :controller => "main",
+ <%= link_to @function.namespace.name, :controller => "main",
:action => "ns",
- :lib => @library.url_friendly_name,
- :ns => @function.ns,
- :version => @function.version %>
+ :lib => @function.library.url_friendly_name,
+ :ns => @function.namespace.name,
+ :version => @function.library.version %>
</span>
</h2>
@@ -194,7 +194,7 @@ $(document).ready(function() {
<% if @function.file %>
<span class="file">
<% if @library.source_base_url %>
- <a href="<%= @library.source_base_url %>/master<%= @ns.source_url %>#L<%= @function.line %>"><%= @function.file %>:<%= @function.line %></a>
+ <a href="<%= @function.library.source_base_url %>/master<%= @function.namespace.source_url %>#L<%= @function.line %>"><%= @function.file %>:<%= @function.line %></a>
<% else %>
<%= @function.file %>:<%= @function.line %>
<% end %>
@@ -212,7 +212,7 @@ $(document).ready(function() {
</div>
<div class="references">
- Vars in <span class="ns"><%= @function.ns %>/</span><%= @function.name %>:
+ Vars in <span class="ns"><%= @function.namespace.name %>/</span><%= @function.name %>:
<% @function.source_references.each do |f|%>
<span class="reference"><a href="<%= f.href %>"><%= f.name %></a></span>
<% end %>
View
8 app/views/main/lib.html.erb
@@ -7,6 +7,12 @@
&nbsp;
</div>
<div class="grid_10">
+ <% if not @library.current %>
+ <div class="version_warning">
+ You're viewing version <%= @library.version %> of <%= @library.name %>.
+ The latest stable version of <%= @library.name %> is <%= Library.current_version_of(@library).version %>.
+ </div>
+ <% end %>
<div class="lib_header">
<div class="short_link versions_nav">
<% Library.versions_of(@library).each do |l| %>
@@ -28,7 +34,7 @@
<% end %>
</div>
<div class="functions_list">
- <% group_into_ns(Function.in_library(@library)).each do |g| %>
+ <% group_into_ns(@library.namespaces.reduce([]) {|coll, ns| coll + ns.functions}).each do |g| %>
<h5><%= g[0] %></h5>
<div class="functions">
<% g[1].each do |f| %>
View
17 app/views/main/ns.html.erb
@@ -6,15 +6,12 @@
&nbsp;
</div>
<div class="grid_10">
- <div class="short_link versions_nav">
- <% Library.versions_of(@library).each do |l| %>
- <% if @library.version == l.version %>
- <span class="selected"><%= l.version %></span>
- <% else %>
- <a href="/<%= l.url_friendly_name %>/<%= l.version %>/<%= @ns.name %>"><%= l.version %></a>
- <% end %>
- <% end %>
+ <% if not @library.current %>
+ <div class="version_warning">
+ You're viewing version <%= @library.version %> of <%= @ns.name %>.
+ The latest stable version of <%= @ns.name %> is <%= Library.current_version_of(@library).version %>.
</div>
+ <% end %>
<% if @ns and @ns.doc != ""%>
<div class="doc">
<h3>DocString</h3>
@@ -29,7 +26,7 @@
<h3>Vars in <%= params[:ns] %></h3>
<div class="functions_list">
- <% group_into_ns(Function.in_library_and_ns(@library, @ns.name)).each do |g| %>
+ <% group_into_ns(@ns.functions).each do |g| %>
<h5><%= g[0] %></h5>
<div class="functions">
<% g[1].each do |f| %>
@@ -39,7 +36,7 @@
:action => 'function',
:lib => @library.url_friendly_name,
:version => params[:version],
- :ns => f[:ns],
+ :ns => @ns.name,
:function => f[:url_friendly_name] %>
</span>
<% end %>
View
6 app/views/see_also/_see_also_content.html.erb
@@ -1,6 +1,6 @@
<%
f = sa.to_function
-lib = Library.find_by_name(f.library)
+lib = f.library
belongs_to_user = current_user_session && (current_user == sa.user)
%>
<div>
@@ -16,12 +16,12 @@ belongs_to_user = current_user_session && (current_user == sa.user)
<% end %>
</div>
- <%= link_to "<span class='ns'>#{f.ns}/</span><span class='name'>#{f.name}</span>",
+ <%= link_to "<span class='ns'>#{f.namespace.name}/</span><span class='name'>#{f.name}</span>",
:controller => 'main',
:action => 'function',
:lib => lib.url_friendly_name,
:version => nil,
- :ns => f.ns,
+ :ns => f.namespace.name,
:function => f.url_friendly_name %>
<p class="shortdoc"><%= f.shortdoc %></p>
View
1  config/database.example.yml
@@ -1,4 +1,5 @@
shared: &shared
+ host: 127.0.0.1 #thinking_sphinx dosen't like sock, have to use ip
adapter: mysql
pool: 5
min_messages: warning
View
45 db/migrate/20101010021829_add_lib_ns_var_rels.rb
@@ -0,0 +1,45 @@
+class AddLibNsVarRels < ActiveRecord::Migration
+ def self.up
+ add_column :functions, :namespace_id, :integer
+ add_column :namespaces, :library_id, :integer
+
+ functions = Function.find(:all)
+ namespaces = Namespace.find(:all)
+
+ functions.each do |f|
+ ns_id = Namespace.find_by_name_and_version(f.ns, f.version).id rescue nil
+
+ if not ns_id
+ ns_id = Namespace.find_by_name(f.ns).id rescue nil
+ end
+
+ if ns_id
+ f.namespace_id = ns_id
+ f.save
+ end
+ end
+
+ namespaces.each do |n|
+ f = Function.find_by_ns_and_version(n.name, n.version)
+ if not f
+ f = Function.find_by_ns(n.name)
+ end
+
+ if f
+ l = Library.find_by_name_and_version(f.library, f.version)
+ if not l
+ l = Library.find_by_name(f.library)
+ end
+
+ if l
+ n.library_id = l.id
+ n.save
+ end
+ end
+ end
+
+ end
+
+ def self.down
+ end
+end
View
9 db/migrate/20101010034343_remove_lib_ns_from_var.rb
@@ -0,0 +1,9 @@
+class RemoveLibNsFromVar < ActiveRecord::Migration
+ def self.up
+ remove_column :functions, :library
+ remove_column :functions, :ns
+ end
+
+ def self.down
+ end
+end
View
8 db/schema.rb
@@ -9,13 +9,13 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101006031711) do
+ActiveRecord::Schema.define(:version => 20101010034343) do
create_table "comments", :force => true do |t|
t.integer "commentable_id", :default => 0
t.string "commentable_type", :limit => 15, :default => ""
t.string "title", :default => ""
- t.text "body", :default => ""
+ t.text "body"
t.string "subject", :default => ""
t.integer "user_id", :default => 0, :null => false
t.integer "parent_id"
@@ -55,8 +55,6 @@
end
create_table "functions", :force => true do |t|
- t.string "library"
- t.string "ns"
t.string "name"
t.string "file"
t.string "line"
@@ -70,6 +68,7 @@
t.string "shortdoc", :limit => 70
t.string "version"
t.string "url_friendly_name"
+ t.integer "namespace_id"
end
create_table "libraries", :force => true do |t|
@@ -111,6 +110,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.string "version"
+ t.integer "library_id"
end
create_table "open_id_authentication_associations", :force => true do |t|
View
16 test/fixtures/functions.yml
@@ -8,9 +8,9 @@
map:
id: 1
- library: Clojure Core
- ns: clojure.core
+ namespace_id: 1
name: map
+ url_friendly_name: map
file: clojure/core.clj
line: 2079
arglists_comp: "[f coll]|[f c1 c2]|[f c1 c2 c3]|[f c1 c2 c3 & colls]"
@@ -64,21 +64,21 @@ f should accept number-of-colls arguments.\"
dummy:
id: 2
- library: "not_found"
- ns: dummy.ns
+ namespace_id: 2
name: dummyname
+ url_friendly_name: dummyname
clojure_core_dummy:
id: 3
- library: "Clojure Core"
- ns: clojure.dummy.ns
+ namespace_id: 2
name: clojure.core
+ url_friendly_name: clojure.core
clojure_core_plus:
id: 4
- library: "Clojure Core"
- ns: clojure.core
+ namespace_id: 1
name: "+"
+ url_friendly_name: "+"
file: "clojure/core.clj"
line: 809
arglists_comp: "[]|[x]|[x y]|[x y & more]"
View
4 test/fixtures/libraries.yml
@@ -6,7 +6,11 @@
# two:
# column: value
clojure_core:
+ id: 1
name: Clojure Core
+ url_friendly_name: clojure_core
+ version: "1.2.0"
+ current: true
description: "The user contributions library, clojure.contrib, is a collection of namespaces each of which implements features that we believe may be useful to a large part of the Clojure community."
site_url: http://richhickey.github.com/clojure-contrib/
source_base_url: http://github.com/richhickey/clojure-contrib/blob/master/src/main/clojure
View
6 test/fixtures/namespaces.yml
@@ -8,5 +8,11 @@
clojure_core:
id: 1
+ library_id: 1
name: clojure.core
doc: "Fundamental library of the Clojure language"
+
+clojure_dummy:
+ id: 2
+ name: clojure.dummy.ns
+ doc: "hello world"
View
8 test/functional/application_controller_test.rb
@@ -46,13 +46,5 @@ class ApplicationControllerTest < ActionController::TestCase
end
end
- context "from the library not_found" do
- should "give a single recent update of the type Example" do
- recent = @app_controller.send(:find_recently_updated, 10, "not_found")
- assert_equal recent.size, 1
- assert recent[0].instance_of? Example
- end
- end
-
end
end
View
22 test/functional/main_controller_test.rb
@@ -12,8 +12,12 @@ class MainControllerTest < ActionController::TestCase
should_succeed :index
should_succeed :libs
- context "The function page" do
- should_succeed :function_short_link, {:id => 1}
+ context "The function short link action" do
+ setup do
+ get :function_short_link, {:id => 1}
+ end
+
+ should respond_with 302
context "with an invalid function" do
setup do
@@ -22,18 +26,10 @@ class MainControllerTest < ActionController::TestCase
should respond_with 404
end
-
- context "with a valid function, but an invalid library" do
- setup do
- get :function_short_link, :id => 2
- end
-
- should respond_with 404
- end
end
context "the ns page" do
- should_succeed :ns, {:lib => 'Clojure Core', :ns => 'clojure.core'}
+ should_succeed :ns, {:lib => 'clojure_core', :ns => 'clojure.core'}
context "with an invalid library" do
setup do
@@ -45,7 +41,7 @@ class MainControllerTest < ActionController::TestCase
context "with a valid library and an invalid ns" do
setup do
- get :ns, :lib => 'Clojure Core', :ns => 'not found'
+ get :ns, :lib => 'clojure_core', :ns => 'not found'
end
should respond_with 404
@@ -53,7 +49,7 @@ class MainControllerTest < ActionController::TestCase
end
context "The library page" do
- should_succeed :lib, :lib => "Clojure Core"
+ should_succeed :lib, :lib => "clojure_core"
context "with a library not in the database" do
setup do
View
30 test/unit/function_test.rb
@@ -14,34 +14,4 @@ class FunctionTest < ActiveSupport::TestCase
assert_equal '/v/1', @f.href
end
end
-
- context "Getting all libraries" do
- setup do
- @ls = Function.libraries
- end
-
- should "find 1 library" do
- assert_equal 2, @ls.size
- end
- end
-
- context "Getting functions in library Clojure Core" do
- setup do
- @fs = Function.in_library("Clojure Core")
- end
-
- should "find 3 functions" do
- assert (@fs.size == 3)
- end
- end
-
- context "Getting functions in library Clojure Core and ns clojure.core" do
- setup do
- @fs = Function.in_library_and_ns("Clojure Core", "clojure.core")
- end
-
- should "find 2 functions" do
- assert_equal 2, @fs.size
- end
- end
end
View
6 test/unit/helpers/appication_helper_test.rb
@@ -4,12 +4,12 @@ class ApplicationHelperTest < ActionView::TestCase
context "functions_group_into_alpha" do
setup do
- fs = Function.in_library('Clojure Core')
+ fs = Library.find_by_name("Clojure Core").namespaces.reduce([]){|coll, ns| coll + ns.functions }
@groups = functions_group_into_alpha(fs)
end
- should "result in 3 groups when using functions from clojure core" do
- assert_equal 3, @groups.size
+ should "result in 2 groups when using functions from clojure core" do
+ assert_equal 2, @groups.size
end
should "have the first function in the group with name '+' as '+'" do
Please sign in to comment.
Something went wrong with that request. Please try again.