Revision 1298:4f746d8966dd .svn/pristine/43
| .svn/pristine/43/4319c6d41e87c8e5f7a1d9a565f8d9f540e96297.svn-base | ||
|---|---|---|
| 1 |
<h2><%= l(:label_plugins) %></h2> |
|
| 2 |
|
|
| 3 |
<% if @plugins.any? %> |
|
| 4 |
<table class="list plugins"> |
|
| 5 |
<% @plugins.each do |plugin| %> |
|
| 6 |
<tr id="plugin-<%= plugin.id %>" class="<%= cycle('odd', 'even') %>">
|
|
| 7 |
<td><span class="name"><%=h plugin.name %></span> |
|
| 8 |
<%= content_tag('span', h(plugin.description), :class => 'description') unless plugin.description.blank? %>
|
|
| 9 |
<%= content_tag('span', link_to(h(plugin.url), plugin.url), :class => 'url') unless plugin.url.blank? %>
|
|
| 10 |
</td> |
|
| 11 |
<td class="author"><%= plugin.author_url.blank? ? h(plugin.author) : link_to(h(plugin.author), plugin.author_url) %></td> |
|
| 12 |
<td class="version"><%=h plugin.version %></td> |
|
| 13 |
<td class="configure"><%= link_to(l(:button_configure), plugin_settings_path(plugin)) if plugin.configurable? %></td> |
|
| 14 |
</tr> |
|
| 15 |
<% end %> |
|
| 16 |
</table> |
|
| 17 |
<% else %> |
|
| 18 |
<p class="nodata"><%= l(:label_no_data) %></p> |
|
| 19 |
<% end %> |
|
| .svn/pristine/43/431e564a1e03f4cc7d0102d7d18816df7d2cc0e3.svn-base | ||
|---|---|---|
| 1 |
require File.expand_path('../../../test_helper', __FILE__)
|
|
| 2 |
|
|
| 3 |
class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest |
|
| 4 |
fixtures :projects, :trackers, :issue_statuses, :issues, |
|
| 5 |
:enumerations, :users, :issue_categories, |
|
| 6 |
:projects_trackers, |
|
| 7 |
:roles, |
|
| 8 |
:member_roles, |
|
| 9 |
:members, |
|
| 10 |
:enabled_modules, |
|
| 11 |
:workflows |
|
| 12 |
|
|
| 13 |
def setup |
|
| 14 |
Setting.rest_api_enabled = '0' |
|
| 15 |
Setting.login_required = '1' |
|
| 16 |
end |
|
| 17 |
|
|
| 18 |
def teardown |
|
| 19 |
Setting.rest_api_enabled = '1' |
|
| 20 |
Setting.login_required = '0' |
|
| 21 |
end |
|
| 22 |
|
|
| 23 |
# Using the NewsController because it's a simple API. |
|
| 24 |
context "get /news with the API disabled" do |
|
| 25 |
|
|
| 26 |
context "in :xml format" do |
|
| 27 |
context "with a valid api token" do |
|
| 28 |
setup do |
|
| 29 |
@user = User.generate_with_protected! |
|
| 30 |
@token = Token.generate!(:user => @user, :action => 'api') |
|
| 31 |
get "/news.xml?key=#{@token.value}"
|
|
| 32 |
end |
|
| 33 |
|
|
| 34 |
should_respond_with :unauthorized |
|
| 35 |
should_respond_with_content_type :xml |
|
| 36 |
should "not login as the user" do |
|
| 37 |
assert_equal User.anonymous, User.current |
|
| 38 |
end |
|
| 39 |
end |
|
| 40 |
|
|
| 41 |
context "with a valid HTTP authentication" do |
|
| 42 |
setup do |
|
| 43 |
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') |
|
| 44 |
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') |
|
| 45 |
get "/news.xml", nil, :authorization => @authorization |
|
| 46 |
end |
|
| 47 |
|
|
| 48 |
should_respond_with :unauthorized |
|
| 49 |
should_respond_with_content_type :xml |
|
| 50 |
should "not login as the user" do |
|
| 51 |
assert_equal User.anonymous, User.current |
|
| 52 |
end |
|
| 53 |
end |
|
| 54 |
|
|
| 55 |
context "with a valid HTTP authentication using the API token" do |
|
| 56 |
setup do |
|
| 57 |
@user = User.generate_with_protected! |
|
| 58 |
@token = Token.generate!(:user => @user, :action => 'api') |
|
| 59 |
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X') |
|
| 60 |
get "/news.xml", nil, :authorization => @authorization |
|
| 61 |
end |
|
| 62 |
|
|
| 63 |
should_respond_with :unauthorized |
|
| 64 |
should_respond_with_content_type :xml |
|
| 65 |
should "not login as the user" do |
|
| 66 |
assert_equal User.anonymous, User.current |
|
| 67 |
end |
|
| 68 |
end |
|
| 69 |
end |
|
| 70 |
|
|
| 71 |
context "in :json format" do |
|
| 72 |
context "with a valid api token" do |
|
| 73 |
setup do |
|
| 74 |
@user = User.generate_with_protected! |
|
| 75 |
@token = Token.generate!(:user => @user, :action => 'api') |
|
| 76 |
get "/news.json?key=#{@token.value}"
|
|
| 77 |
end |
|
| 78 |
|
|
| 79 |
should_respond_with :unauthorized |
|
| 80 |
should_respond_with_content_type :json |
|
| 81 |
should "not login as the user" do |
|
| 82 |
assert_equal User.anonymous, User.current |
|
| 83 |
end |
|
| 84 |
end |
|
| 85 |
|
|
| 86 |
context "with a valid HTTP authentication" do |
|
| 87 |
setup do |
|
| 88 |
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') |
|
| 89 |
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') |
|
| 90 |
get "/news.json", nil, :authorization => @authorization |
|
| 91 |
end |
|
| 92 |
|
|
| 93 |
should_respond_with :unauthorized |
|
| 94 |
should_respond_with_content_type :json |
|
| 95 |
should "not login as the user" do |
|
| 96 |
assert_equal User.anonymous, User.current |
|
| 97 |
end |
|
| 98 |
end |
|
| 99 |
|
|
| 100 |
context "with a valid HTTP authentication using the API token" do |
|
| 101 |
setup do |
|
| 102 |
@user = User.generate_with_protected! |
|
| 103 |
@token = Token.generate!(:user => @user, :action => 'api') |
|
| 104 |
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'DoesNotMatter') |
|
| 105 |
get "/news.json", nil, :authorization => @authorization |
|
| 106 |
end |
|
| 107 |
|
|
| 108 |
should_respond_with :unauthorized |
|
| 109 |
should_respond_with_content_type :json |
|
| 110 |
should "not login as the user" do |
|
| 111 |
assert_equal User.anonymous, User.current |
|
| 112 |
end |
|
| 113 |
end |
|
| 114 |
|
|
| 115 |
end |
|
| 116 |
end |
|
| 117 |
end |
|
| .svn/pristine/43/43272555ea477da0c1b59cf98e2f63d68056c98b.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require 'redmine/scm/adapters/darcs_adapter' |
|
| 19 |
|
|
| 20 |
class Repository::Darcs < Repository |
|
| 21 |
validates_presence_of :url, :log_encoding |
|
| 22 |
|
|
| 23 |
def self.human_attribute_name(attribute_key_name) |
|
| 24 |
attr_name = attribute_key_name |
|
| 25 |
if attr_name == "url" |
|
| 26 |
attr_name = "path_to_repository" |
|
| 27 |
end |
|
| 28 |
super(attr_name) |
|
| 29 |
end |
|
| 30 |
|
|
| 31 |
def self.scm_adapter_class |
|
| 32 |
Redmine::Scm::Adapters::DarcsAdapter |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
def self.scm_name |
|
| 36 |
'Darcs' |
|
| 37 |
end |
|
| 38 |
|
|
| 39 |
def supports_directory_revisions? |
|
| 40 |
true |
|
| 41 |
end |
|
| 42 |
|
|
| 43 |
def entry(path=nil, identifier=nil) |
|
| 44 |
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) |
|
| 45 |
scm.entry(path, patch.nil? ? nil : patch.scmid) |
|
| 46 |
end |
|
| 47 |
|
|
| 48 |
def entries(path=nil, identifier=nil) |
|
| 49 |
patch = nil |
|
| 50 |
if ! identifier.nil? |
|
| 51 |
patch = changesets.find_by_revision(identifier) |
|
| 52 |
return nil if patch.nil? |
|
| 53 |
end |
|
| 54 |
entries = scm.entries(path, patch.nil? ? nil : patch.scmid) |
|
| 55 |
if entries |
|
| 56 |
entries.each do |entry| |
|
| 57 |
# Search the DB for the entry's last change |
|
| 58 |
if entry.lastrev && !entry.lastrev.scmid.blank? |
|
| 59 |
changeset = changesets.find_by_scmid(entry.lastrev.scmid) |
|
| 60 |
end |
|
| 61 |
if changeset |
|
| 62 |
entry.lastrev.identifier = changeset.revision |
|
| 63 |
entry.lastrev.name = changeset.revision |
|
| 64 |
entry.lastrev.time = changeset.committed_on |
|
| 65 |
entry.lastrev.author = changeset.committer |
|
| 66 |
end |
|
| 67 |
end |
|
| 68 |
end |
|
| 69 |
entries |
|
| 70 |
end |
|
| 71 |
|
|
| 72 |
def cat(path, identifier=nil) |
|
| 73 |
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) |
|
| 74 |
scm.cat(path, patch.nil? ? nil : patch.scmid) |
|
| 75 |
end |
|
| 76 |
|
|
| 77 |
def diff(path, rev, rev_to) |
|
| 78 |
patch_from = changesets.find_by_revision(rev) |
|
| 79 |
return nil if patch_from.nil? |
|
| 80 |
patch_to = changesets.find_by_revision(rev_to) if rev_to |
|
| 81 |
if path.blank? |
|
| 82 |
path = patch_from.changes.collect{|change| change.path}.join(' ')
|
|
| 83 |
end |
|
| 84 |
patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil |
|
| 85 |
end |
|
| 86 |
|
|
| 87 |
def fetch_changesets |
|
| 88 |
scm_info = scm.info |
|
| 89 |
if scm_info |
|
| 90 |
db_last_id = latest_changeset ? latest_changeset.scmid : nil |
|
| 91 |
next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 |
|
| 92 |
# latest revision in the repository |
|
| 93 |
scm_revision = scm_info.lastrev.scmid |
|
| 94 |
unless changesets.find_by_scmid(scm_revision) |
|
| 95 |
revisions = scm.revisions('', db_last_id, nil, :with_path => true)
|
|
| 96 |
transaction do |
|
| 97 |
revisions.reverse_each do |revision| |
|
| 98 |
changeset = Changeset.create(:repository => self, |
|
| 99 |
:revision => next_rev, |
|
| 100 |
:scmid => revision.scmid, |
|
| 101 |
:committer => revision.author, |
|
| 102 |
:committed_on => revision.time, |
|
| 103 |
:comments => revision.message) |
|
| 104 |
revision.paths.each do |change| |
|
| 105 |
changeset.create_change(change) |
|
| 106 |
end |
|
| 107 |
next_rev += 1 |
|
| 108 |
end if revisions |
|
| 109 |
end |
|
| 110 |
end |
|
| 111 |
end |
|
| 112 |
end |
|
| 113 |
end |
|
| .svn/pristine/43/4333e2faed9865820292b92a3a8ebf203749d50e.svn-base | ||
|---|---|---|
| 1 |
# encoding: utf-8 |
|
| 2 |
# |
|
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006-2013 Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 |
|
|
| 20 |
module WikiHelper |
|
| 21 |
|
|
| 22 |
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) |
|
| 23 |
pages = pages.group_by(&:parent) unless pages.is_a?(Hash) |
|
| 24 |
s = ''.html_safe |
|
| 25 |
if pages.has_key?(parent) |
|
| 26 |
pages[parent].each do |page| |
|
| 27 |
attrs = "value='#{page.id}'"
|
|
| 28 |
attrs << " selected='selected'" if selected == page |
|
| 29 |
indent = (level > 0) ? (' ' * level * 2 + '» ') : ''
|
|
| 30 |
|
|
| 31 |
s << content_tag('option', (indent + h(page.pretty_title)).html_safe, :value => page.id.to_s, :selected => selected == page) +
|
|
| 32 |
wiki_page_options_for_select(pages, selected, page, level + 1) |
|
| 33 |
end |
|
| 34 |
end |
|
| 35 |
s |
|
| 36 |
end |
|
| 37 |
|
|
| 38 |
def wiki_page_breadcrumb(page) |
|
| 39 |
breadcrumb(page.ancestors.reverse.collect {|parent|
|
|
| 40 |
link_to(h(parent.pretty_title), {:controller => 'wiki', :action => 'show', :id => parent.title, :project_id => parent.project, :version => nil})
|
|
| 41 |
}) |
|
| 42 |
end |
|
| 43 |
end |
|
| .svn/pristine/43/435d200d5b8e7f06b0e465d23cb053a76fc8f49e.svn-base | ||
|---|---|---|
| 1 |
<div class="contextual"> |
|
| 2 |
<%= watcher_link(@news, User.current) %> |
|
| 3 |
<%= link_to(l(:button_edit), |
|
| 4 |
edit_news_path(@news), |
|
| 5 |
:class => 'icon icon-edit', |
|
| 6 |
:accesskey => accesskey(:edit), |
|
| 7 |
:onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_news, @project) %>
|
|
| 8 |
<%= delete_link news_path(@news) if User.current.allowed_to?(:manage_news, @project) %> |
|
| 9 |
</div> |
|
| 10 |
|
|
| 11 |
<h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2> |
|
| 12 |
|
|
| 13 |
<% if authorize_for('news', 'edit') %>
|
|
| 14 |
<div id="edit-news" style="display:none;"> |
|
| 15 |
<%= labelled_form_for :news, @news, :url => news_path(@news), |
|
| 16 |
:html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
|
|
| 17 |
<%= render :partial => 'form', :locals => { :f => f } %>
|
|
| 18 |
<%= submit_tag l(:button_save) %> |
|
| 19 |
<%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> | |
|
| 20 |
<%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %>
|
|
| 21 |
<% end %> |
|
| 22 |
<div id="preview" class="wiki"></div> |
|
| 23 |
</div> |
|
| 24 |
<% end %> |
|
| 25 |
|
|
| 26 |
<p><% unless @news.summary.blank? %><em><%=h @news.summary %></em><br /><% end %> |
|
| 27 |
<span class="author"><%= authoring @news.created_on, @news.author %></span></p> |
|
| 28 |
<div class="wiki"> |
|
| 29 |
<%= textilizable(@news, :description) %> |
|
| 30 |
</div> |
|
| 31 |
<%= link_to_attachments @news %> |
|
| 32 |
<br /> |
|
| 33 |
|
|
| 34 |
<div id="comments" style="margin-bottom:16px;"> |
|
| 35 |
<h3 class="comments"><%= l(:label_comment_plural) %></h3> |
|
| 36 |
<% @comments.each do |comment| %> |
|
| 37 |
<% next if comment.new_record? %> |
|
| 38 |
<div class="contextual"> |
|
| 39 |
<%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
|
|
| 40 |
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %>
|
|
| 41 |
</div> |
|
| 42 |
<h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4> |
|
| 43 |
<%= textilizable(comment.comments) %> |
|
| 44 |
<% end if @comments.any? %> |
|
| 45 |
</div> |
|
| 46 |
|
|
| 47 |
<% if @news.commentable? %> |
|
| 48 |
<p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p> |
|
| 49 |
<%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
|
|
| 50 |
<div class="box"> |
|
| 51 |
<%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %> |
|
| 52 |
<%= wikitoolbar_for 'comment_comments' %> |
|
| 53 |
</div> |
|
| 54 |
<p><%= submit_tag l(:button_add) %></p> |
|
| 55 |
<% end %> |
|
| 56 |
<% end %> |
|
| 57 |
|
|
| 58 |
<% html_title @news.title -%> |
|
| 59 |
|
|
| 60 |
<% content_for :header_tags do %> |
|
| 61 |
<%= stylesheet_link_tag 'scm' %> |
|
| 62 |
<% end %> |
|
| .svn/pristine/43/437c58e98b2bf838355e6ccb0adcad2c75761185.svn-base | ||
|---|---|---|
| 1 |
<h2><%= l(:label_search) %></h2> |
|
| 2 |
|
|
| 3 |
<div class="box"> |
|
| 4 |
<% form_tag({}, :method => :get) do %>
|
|
| 5 |
<%= label_tag "search-input", l(:description_search), :class => "hidden-for-sighted" %> |
|
| 6 |
<p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input' %> |
|
| 7 |
<%= javascript_tag "Field.focus('search-input')" %>
|
|
| 8 |
<%= project_select_tag %> |
|
| 9 |
<%= hidden_field_tag 'all_words', '', :id => nil %> |
|
| 10 |
<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label> |
|
| 11 |
<%= hidden_field_tag 'titles_only', '', :id => nil %> |
|
| 12 |
<label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label> |
|
| 13 |
</p> |
|
| 14 |
<p> |
|
| 15 |
<% @object_types.each do |t| %> |
|
| 16 |
<label><%= check_box_tag t, 1, @scope.include?(t) %> <%= type_label(t) %></label> |
|
| 17 |
<% end %> |
|
| 18 |
</p> |
|
| 19 |
|
|
| 20 |
<p><%= submit_tag l(:button_submit), :name => 'submit' %></p> |
|
| 21 |
<% end %> |
|
| 22 |
</div> |
|
| 23 |
|
|
| 24 |
<% if @results %> |
|
| 25 |
<div id="search-results-counts"> |
|
| 26 |
<%= render_results_by_type(@results_by_type) unless @scope.size == 1 %> |
|
| 27 |
</div> |
|
| 28 |
|
|
| 29 |
<h3><%= l(:label_result_plural) %> (<%= @results_by_type.values.sum %>)</h3> |
|
| 30 |
<dl id="search-results"> |
|
| 31 |
<% @results.each do |e| %> |
|
| 32 |
<dt class="<%= e.event_type %>"><%= content_tag('span', h(e.project), :class => 'project') unless @project == e.project %> <%= link_to highlight_tokens(truncate(h(e.event_title), :length => 255), @tokens), e.event_url %></dt>
|
|
| 33 |
<dd><span class="description"><%= highlight_tokens(h(e.event_description), @tokens) %></span> |
|
| 34 |
<span class="author"><%= format_time(e.event_datetime) %></span></dd> |
|
| 35 |
<% end %> |
|
| 36 |
</dl> |
|
| 37 |
<% end %> |
|
| 38 |
|
|
| 39 |
<p><center> |
|
| 40 |
<% if @pagination_previous_date %> |
|
| 41 |
<%= link_to_content_update("\xc2\xab " + l(:label_previous),
|
|
| 42 |
params.merge(:previous => 1, |
|
| 43 |
:offset => @pagination_previous_date.strftime("%Y%m%d%H%M%S"))) %>
|
|
| 44 |
<% end %> |
|
| 45 |
<% if @pagination_next_date %> |
|
| 46 |
<%= link_to_content_update(l(:label_next) + " \xc2\xbb", |
|
| 47 |
params.merge(:previous => nil, |
|
| 48 |
:offset => @pagination_next_date.strftime("%Y%m%d%H%M%S"))) %>
|
|
| 49 |
<% end %> |
|
| 50 |
</center></p> |
|
| 51 |
|
|
| 52 |
<% html_title(l(:label_search)) -%> |
|
| .svn/pristine/43/43815b2797ad5e2c1f98a876a3c98a313e459bdb.svn-base | ||
|---|---|---|
| 1 |
RUBYTREE - http://rubytree.rubyforge.org |
|
| 2 |
======================================== |
|
| 3 |
|
|
| 4 |
Copyright (c) 2006, 2007 Anupam Sengupta |
|
| 5 |
|
|
| 6 |
All rights reserved. |
|
| 7 |
|
|
| 8 |
Redistribution and use in source and binary forms, with or without modification, |
|
| 9 |
are permitted provided that the following conditions are met: |
|
| 10 |
|
|
| 11 |
- Redistributions of source code must retain the above copyright notice, this |
|
| 12 |
list of conditions and the following disclaimer. |
|
| 13 |
|
|
| 14 |
- Redistributions in binary form must reproduce the above copyright notice, this |
|
| 15 |
list of conditions and the following disclaimer in the documentation and/or |
|
| 16 |
other materials provided with the distribution. |
|
| 17 |
|
|
| 18 |
- Neither the name of the organization nor the names of its contributors may |
|
| 19 |
be used to endorse or promote products derived from this software without |
|
| 20 |
specific prior written permission. |
|
| 21 |
|
|
| 22 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
| 23 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
| 24 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
| 25 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
|
| 26 |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
| 27 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
| 28 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
| 29 |
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
| 30 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
| 31 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| .svn/pristine/43/4384f149ba601f6c60fa67ac6f918ddfc90dc0b6.svn-base | ||
|---|---|---|
| 1 |
# This code lets us redefine existing Rake tasks, which is extremely |
|
| 2 |
# handy for modifying existing Rails rake tasks. |
|
| 3 |
# Credit for the original snippet of code goes to Jeremy Kemper |
|
| 4 |
# http://pastie.caboo.se/9620 |
|
| 5 |
unless Rake::TaskManager.methods.include?('redefine_task')
|
|
| 6 |
module Rake |
|
| 7 |
module TaskManager |
|
| 8 |
def redefine_task(task_class, args, &block) |
|
| 9 |
task_name, arg_names, deps = resolve_args([args]) |
|
| 10 |
task_name = task_class.scope_name(@scope, task_name) |
|
| 11 |
deps = [deps] unless deps.respond_to?(:to_ary) |
|
| 12 |
deps = deps.collect {|d| d.to_s }
|
|
| 13 |
task = @tasks[task_name.to_s] = task_class.new(task_name, self) |
|
| 14 |
task.application = self |
|
| 15 |
task.add_description(@last_description) |
|
| 16 |
@last_description = nil |
|
| 17 |
task.enhance(deps, &block) |
|
| 18 |
task |
|
| 19 |
end |
|
| 20 |
|
|
| 21 |
end |
|
| 22 |
class Task |
|
| 23 |
class << self |
|
| 24 |
def redefine_task(args, &block) |
|
| 25 |
Rake.application.redefine_task(self, [args], &block) |
|
| 26 |
end |
|
| 27 |
end |
|
| 28 |
end |
|
| 29 |
end |
|
| 30 |
end |
|
| 31 |
|
|
| 32 |
namespace :db do |
|
| 33 |
namespace :migrate do |
|
| 34 |
desc 'Migrate database and plugins to current status.' |
|
| 35 |
task :all => [ 'db:migrate', 'db:migrate:plugins' ] |
|
| 36 |
|
|
| 37 |
desc 'Migrate plugins to current status.' |
|
| 38 |
task :plugins => :environment do |
|
| 39 |
Engines.plugins.each do |plugin| |
|
| 40 |
next unless plugin.respond_to?(:migration_directory) |
|
| 41 |
next unless File.exists? plugin.migration_directory |
|
| 42 |
puts "Migrating plugin #{plugin.name} ..."
|
|
| 43 |
plugin.migrate |
|
| 44 |
end |
|
| 45 |
end |
|
| 46 |
|
|
| 47 |
desc 'For engines coming from Rails version < 2.0 or for those previously updated to work with Sven Fuch\'s fork of engines, you need to upgrade the schema info table' |
|
| 48 |
task :upgrade_plugin_migrations => :environment do |
|
| 49 |
svens_fork_table_name = 'plugin_schema_migrations' |
|
| 50 |
|
|
| 51 |
# Check if app was previously using Sven's fork |
|
| 52 |
if ActiveRecord::Base.connection.table_exists?(svens_fork_table_name) |
|
| 53 |
old_sm_table = svens_fork_table_name |
|
| 54 |
else |
|
| 55 |
old_sm_table = ActiveRecord::Migrator.proper_table_name(Engines.schema_info_table) |
|
| 56 |
end |
|
| 57 |
|
|
| 58 |
unless ActiveRecord::Base.connection.table_exists?(old_sm_table) |
|
| 59 |
abort "Cannot find old migration table - assuming nothing needs to be done" |
|
| 60 |
end |
|
| 61 |
|
|
| 62 |
# There are two forms of the engines schema info - pre-fix_plugin_migrations and post |
|
| 63 |
# We need to figure this out before we continue. |
|
| 64 |
|
|
| 65 |
results = ActiveRecord::Base.connection.select_rows( |
|
| 66 |
"SELECT version, plugin_name FROM #{old_sm_table}"
|
|
| 67 |
).uniq |
|
| 68 |
|
|
| 69 |
def insert_new_version(plugin_name, version) |
|
| 70 |
version_string = "#{version}-#{plugin_name}"
|
|
| 71 |
new_sm_table = ActiveRecord::Migrator.schema_migrations_table_name |
|
| 72 |
|
|
| 73 |
# Check if the row already exists for some reason - maybe run this task more than once. |
|
| 74 |
return if ActiveRecord::Base.connection.select_rows("SELECT * FROM #{new_sm_table} WHERE version = #{version_string.dump.gsub("\"", "'")}").size > 0
|
|
| 75 |
|
|
| 76 |
puts "Inserting new version #{version} for plugin #{plugin_name}.."
|
|
| 77 |
ActiveRecord::Base.connection.insert("INSERT INTO #{new_sm_table} (version) VALUES (#{version_string.dump.gsub("\"", "'")})")
|
|
| 78 |
end |
|
| 79 |
|
|
| 80 |
# We need to figure out if they already used "fix_plugin_migrations" |
|
| 81 |
versions = {}
|
|
| 82 |
results.each do |r| |
|
| 83 |
versions[r[1]] ||= [] |
|
| 84 |
versions[r[1]] << r[0].to_i |
|
| 85 |
end |
|
| 86 |
|
|
| 87 |
if versions.values.find{ |v| v.size > 1 } == nil
|
|
| 88 |
puts "Fixing migration info" |
|
| 89 |
# We only have one listed migration per plugin - this is pre-fix_plugin_migrations, |
|
| 90 |
# so we build all versions required. In this case, all migrations should |
|
| 91 |
versions.each do |plugin_name, version| |
|
| 92 |
version = version[0] # There is only one version |
|
| 93 |
|
|
| 94 |
# We have to make an assumption that numeric migrations won't get this long.. |
|
| 95 |
# I'm not sure if there is a better assumption, it should work in all |
|
| 96 |
# current cases.. (touch wood..) |
|
| 97 |
if version.to_s.size < "YYYYMMDDHHMMSS".size |
|
| 98 |
# Insert version records for each migration |
|
| 99 |
(1..version).each do |v| |
|
| 100 |
insert_new_version(plugin_name, v) |
|
| 101 |
end |
|
| 102 |
else |
|
| 103 |
# If the plugin is new-format "YYYYMMDDHHMMSS", we just copy it across... |
|
| 104 |
# The case in which this occurs is very rare.. |
|
| 105 |
insert_new_version(plugin_name, version) |
|
| 106 |
end |
|
| 107 |
end |
|
| 108 |
else |
|
| 109 |
puts "Moving migration info" |
|
| 110 |
# We have multiple migrations listed per plugin - thus we can assume they have |
|
| 111 |
# already applied fix_plugin_migrations - we just copy it across verbatim |
|
| 112 |
versions.each do |plugin_name, version| |
|
| 113 |
version.each { |v| insert_new_version(plugin_name, v) }
|
|
| 114 |
end |
|
| 115 |
end |
|
| 116 |
|
|
| 117 |
puts "Migration info successfully migrated - removing old schema info table" |
|
| 118 |
ActiveRecord::Base.connection.drop_table(old_sm_table) |
|
| 119 |
end |
|
| 120 |
|
|
| 121 |
desc 'Migrate a specified plugin.' |
|
| 122 |
task(:plugin => :environment) do |
|
| 123 |
name = ENV['NAME'] |
|
| 124 |
if plugin = Engines.plugins[name] |
|
| 125 |
version = ENV['VERSION'] |
|
| 126 |
puts "Migrating #{plugin.name} to " + (version ? "version #{version}" : 'latest version') + " ..."
|
|
| 127 |
plugin.migrate(version ? version.to_i : nil) |
|
| 128 |
else |
|
| 129 |
puts "Plugin #{name} does not exist."
|
|
| 130 |
end |
|
| 131 |
end |
|
| 132 |
end |
|
| 133 |
end |
|
| 134 |
|
|
| 135 |
|
|
| 136 |
namespace :db do |
|
| 137 |
namespace :fixtures do |
|
| 138 |
namespace :plugins do |
|
| 139 |
|
|
| 140 |
desc "Load plugin fixtures into the current environment's database." |
|
| 141 |
task :load => :environment do |
|
| 142 |
require 'active_record/fixtures' |
|
| 143 |
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) |
|
| 144 |
Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', ENV['PLUGIN'] || '**', |
|
| 145 |
'test', 'fixtures', '*.yml')).each do |fixture_file| |
|
| 146 |
Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) |
|
| 147 |
end |
|
| 148 |
end |
|
| 149 |
|
|
| 150 |
end |
|
| 151 |
end |
|
| 152 |
end |
|
| 153 |
|
|
| 154 |
# this is just a modification of the original task in railties/lib/tasks/documentation.rake, |
|
| 155 |
# because the default task doesn't support subdirectories like <plugin>/app or |
|
| 156 |
# <plugin>/component. These tasks now include every file under a plugin's load paths (see |
|
| 157 |
# Plugin#load_paths). |
|
| 158 |
namespace :doc do |
|
| 159 |
|
|
| 160 |
plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
|
|
| 161 |
|
|
| 162 |
namespace :plugins do |
|
| 163 |
|
|
| 164 |
# Define doc tasks for each plugin |
|
| 165 |
plugins.each do |plugin| |
|
| 166 |
desc "Create plugin documentation for '#{plugin}'"
|
|
| 167 |
Rake::Task.redefine_task(plugin => :environment) do |
|
| 168 |
plugin_base = RAILS_ROOT + "/vendor/plugins/#{plugin}"
|
|
| 169 |
options = [] |
|
| 170 |
files = Rake::FileList.new |
|
| 171 |
options << "-o doc/plugins/#{plugin}"
|
|
| 172 |
options << "--title '#{plugin.titlecase} Plugin Documentation'"
|
|
| 173 |
options << '--line-numbers' << '--inline-source' |
|
| 174 |
options << '-T html' |
|
| 175 |
|
|
| 176 |
# Include every file in the plugin's load_paths (see Plugin#load_paths) |
|
| 177 |
if Engines.plugins[plugin] |
|
| 178 |
files.include("#{plugin_base}/{#{Engines.plugins[plugin].load_paths.join(",")}}/**/*.rb")
|
|
| 179 |
end |
|
| 180 |
if File.exists?("#{plugin_base}/README")
|
|
| 181 |
files.include("#{plugin_base}/README")
|
|
| 182 |
options << "--main '#{plugin_base}/README'"
|
|
| 183 |
end |
|
| 184 |
files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG")
|
|
| 185 |
|
|
| 186 |
if files.empty? |
|
| 187 |
puts "No source files found in #{plugin_base}. No documentation will be generated."
|
|
| 188 |
else |
|
| 189 |
options << files.to_s |
|
| 190 |
sh %(rdoc #{options * ' '})
|
|
| 191 |
end |
|
| 192 |
end |
|
| 193 |
end |
|
| 194 |
end |
|
| 195 |
end |
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
namespace :test do |
|
| 200 |
task :warn_about_multiple_plugin_testing_with_engines do |
|
| 201 |
puts %{-~============== A Moste Polite Warninge ===========================~-
|
|
| 202 |
|
|
| 203 |
You may experience issues testing multiple plugins at once when using |
|
| 204 |
the code-mixing features that the engines plugin provides. If you do |
|
| 205 |
experience any problems, please test plugins individually, i.e. |
|
| 206 |
|
|
| 207 |
$ rake test:plugins PLUGIN=my_plugin |
|
| 208 |
|
|
| 209 |
or use the per-type plugin test tasks: |
|
| 210 |
|
|
| 211 |
$ rake test:plugins:units |
|
| 212 |
$ rake test:plugins:functionals |
|
| 213 |
$ rake test:plugins:integration |
|
| 214 |
$ rake test:plugins:all |
|
| 215 |
|
|
| 216 |
Report any issues on http://dev.rails-engines.org. Thanks! |
|
| 217 |
|
|
| 218 |
-~===============( ... as you were ... )============================~-} |
|
| 219 |
end |
|
| 220 |
|
|
| 221 |
namespace :engines do |
|
| 222 |
|
|
| 223 |
def engine_plugins |
|
| 224 |
Dir["vendor/plugins/*"].select { |f| File.directory?(File.join(f, "app")) }.map { |f| File.basename(f) }.join(",")
|
|
| 225 |
end |
|
| 226 |
|
|
| 227 |
desc "Run tests from within engines plugins (plugins with an 'app' directory)" |
|
| 228 |
task :all => [:units, :functionals, :integration] |
|
| 229 |
|
|
| 230 |
desc "Run unit tests from within engines plugins (plugins with an 'app' directory)" |
|
| 231 |
Rake::TestTask.new(:units => "test:plugins:setup_plugin_fixtures") do |t| |
|
| 232 |
t.pattern = "vendor/plugins/{#{ENV['PLUGIN'] || engine_plugins}}/test/unit/**/*_test.rb"
|
|
| 233 |
t.verbose = true |
|
| 234 |
end |
|
| 235 |
|
|
| 236 |
desc "Run functional tests from within engines plugins (plugins with an 'app' directory)" |
|
| 237 |
Rake::TestTask.new(:functionals => "test:plugins:setup_plugin_fixtures") do |t| |
|
| 238 |
t.pattern = "vendor/plugins/{#{ENV['PLUGIN'] || engine_plugins}}/test/functional/**/*_test.rb"
|
|
| 239 |
t.verbose = true |
|
| 240 |
end |
|
| 241 |
|
|
| 242 |
desc "Run integration tests from within engines plugins (plugins with an 'app' directory)" |
|
| 243 |
Rake::TestTask.new(:integration => "test:plugins:setup_plugin_fixtures") do |t| |
|
| 244 |
t.pattern = "vendor/plugins/{#{ENV['PLUGIN'] || engine_plugins}}/test/integration/**/*_test.rb"
|
|
| 245 |
t.verbose = true |
|
| 246 |
end |
|
| 247 |
end |
|
| 248 |
|
|
| 249 |
namespace :plugins do |
|
| 250 |
|
|
| 251 |
desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)" |
|
| 252 |
task :all => [:warn_about_multiple_plugin_testing_with_engines, |
|
| 253 |
:units, :functionals, :integration] |
|
| 254 |
|
|
| 255 |
desc "Run all plugin unit tests" |
|
| 256 |
Rake::TestTask.new(:units => :setup_plugin_fixtures) do |t| |
|
| 257 |
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/unit/**/*_test.rb"
|
|
| 258 |
t.verbose = true |
|
| 259 |
end |
|
| 260 |
|
|
| 261 |
desc "Run all plugin functional tests" |
|
| 262 |
Rake::TestTask.new(:functionals => :setup_plugin_fixtures) do |t| |
|
| 263 |
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/functional/**/*_test.rb"
|
|
| 264 |
t.verbose = true |
|
| 265 |
end |
|
| 266 |
|
|
| 267 |
desc "Integration test engines" |
|
| 268 |
Rake::TestTask.new(:integration => :setup_plugin_fixtures) do |t| |
|
| 269 |
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/integration/**/*_test.rb"
|
|
| 270 |
t.verbose = true |
|
| 271 |
end |
|
| 272 |
|
|
| 273 |
desc "Mirrors plugin fixtures into a single location to help plugin tests" |
|
| 274 |
task :setup_plugin_fixtures => :environment do |
|
| 275 |
Engines::Testing.setup_plugin_fixtures |
|
| 276 |
end |
|
| 277 |
|
|
| 278 |
# Patch the default plugin testing task to have setup_plugin_fixtures as a prerequisite |
|
| 279 |
Rake::Task["test:plugins"].prerequisites << "test:plugins:setup_plugin_fixtures" |
|
| 280 |
end |
|
| 281 |
end |
|
Also available in: Unified diff