Commit eacea15a2156200fb363508e1bd92fc48226345b

Authored by Valery Sizov
1 parent df27ec29

wiki base sceleton

app/controllers/wikis_controller.rb 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +class WikisController < ApplicationController
  2 + before_filter :project
  3 + layout "project"
  4 + respond_to :html
  5 +
  6 + def show
  7 + @wiki = @project.wikis.find_by_slug(params[:id])
  8 + respond_with(@wiki)
  9 + end
  10 +
  11 + def new
  12 + @wiki = Wiki.new
  13 +
  14 + respond_to do |format|
  15 + format.html # new.html.erb
  16 + format.json { render json: @wiki }
  17 + end
  18 + end
  19 +
  20 + def edit
  21 + @wiki = Wiki.find(params[:id])
  22 + end
  23 +
  24 + def create
  25 + @wiki = Wiki.new(params[:wiki])
  26 +
  27 + respond_to do |format|
  28 + if @wiki.save
  29 + format.html { redirect_to @wiki, notice: 'Wiki was successfully created.' }
  30 + format.json { render json: @wiki, status: :created, location: @wiki }
  31 + else
  32 + format.html { render action: "new" }
  33 + format.json { render json: @wiki.errors, status: :unprocessable_entity }
  34 + end
  35 + end
  36 + end
  37 +
  38 + def update
  39 + @wiki = Wiki.find(params[:id])
  40 +
  41 + respond_to do |format|
  42 + if @wiki.update_attributes(params[:wiki])
  43 + format.html { redirect_to @wiki, notice: 'Wiki was successfully updated.' }
  44 + format.json { head :no_content }
  45 + else
  46 + format.html { render action: "edit" }
  47 + format.json { render json: @wiki.errors, status: :unprocessable_entity }
  48 + end
  49 + end
  50 + end
  51 +
  52 + def destroy
  53 + @wiki = Wiki.find(params[:id])
  54 + @wiki.destroy
  55 +
  56 + respond_to do |format|
  57 + format.html { redirect_to wikis_url }
  58 + format.json { head :no_content }
  59 + end
  60 + end
  61 +end
... ...
app/models/project.rb
... ... @@ -12,6 +12,7 @@ class Project &lt; ActiveRecord::Base
12 12 has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
13 13 has_many :web_hooks, :dependent => :destroy
14 14 has_many :protected_branches, :dependent => :destroy
  15 + has_many :wikis, :dependent => :destroy
15 16  
16 17 acts_as_taggable
17 18  
... ...
app/models/wiki.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +class Wiki < ActiveRecord::Base
  2 + belongs_to :project
  3 +
  4 + validates :content, :title, :presence => true
  5 + validates :title, :length => 1..250,
  6 + :uniqueness => {:scope => :project_id, :case_sensitive => false}
  7 +
  8 + before_save :set_slug
  9 +
  10 +
  11 + def to_param
  12 + slug
  13 + end
  14 +
  15 + protected
  16 +
  17 + def set_slug
  18 + self.slug = self.title.parameterize
  19 + end
  20 +end
... ...
app/views/layouts/_project_menu.html.haml
... ... @@ -11,6 +11,7 @@
11 11 - if @project.issues_enabled
12 12 = link_to project_issues_filter_path(@project), :class => (controller.controller_name == "issues") ? "current" : nil do
13 13 Issues
  14 +
14 15 - if @project.merge_requests_enabled
15 16 = link_to project_merge_requests_path(@project), :class => (controller.controller_name == "merge_requests") ? "current" : nil do
16 17 Merge Requests
... ... @@ -18,3 +19,7 @@
18 19 - if @project.wall_enabled
19 20 = link_to wall_project_path(@project), :class => current_page?(:controller => "projects", :action => "wall", :id => @project) ? "current" : nil do
20 21 Wall
  22 +
  23 + - if @project.wiki_enabled
  24 + -#= link_to project_wikis_path(@project), :class => current_page?(:controller => "projects", :action => "wiki", :id => @project) ? "current" : nil do
  25 + Wiki
... ...
app/views/projects/_form.html.haml
... ... @@ -41,6 +41,10 @@
41 41 .clearfix
42 42 = f.label :wall_enabled, "Wall"
43 43 .input= f.check_box :wall_enabled
  44 +
  45 + .clearfix
  46 + = f.label :wiki_enabled, "Wiki"
  47 + .input= f.check_box :wiki_enabled
44 48  
45 49 .clearfix
46 50 = f.label :description
... ...
app/views/wikis/_form.html.haml 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 += form_for @wiki do |f|
  2 + -if @wiki.errors.any?
  3 + #error_explanation
  4 + %h2= "#{pluralize(@wiki.errors.count, "error")} prohibited this wiki from being saved:"
  5 + %ul
  6 + - @wiki.errors.full_messages.each do |msg|
  7 + %li= msg
  8 +
  9 + .field
  10 + = f.label :title
  11 + = f.text_field :title
  12 + .field
  13 + = f.label :content
  14 + = f.text_area :content
  15 + .actions
  16 + = f.submit 'Save'
... ...
app/views/wikis/edit.html.haml 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +%h1 Editing wiki
  2 +
  3 += render 'form'
  4 +
  5 += link_to 'Show', @wiki
  6 +\|
  7 += link_to 'Back', wikis_path
... ...
app/views/wikis/index.html.haml 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +%h1 Listing wikis
  2 +
  3 +%table
  4 + %tr
  5 + %th Title
  6 + %th Content
  7 + %th
  8 + %th
  9 + %th
  10 +
  11 + - @wikis.each do |wiki|
  12 + %tr
  13 + %td= wiki.title
  14 + %td= wiki.content
  15 + %td= link_to 'Show', wiki
  16 + %td= link_to 'Edit', edit_wiki_path(wiki)
  17 + %td= link_to 'Destroy', wiki, :confirm => 'Are you sure?', :method => :delete
  18 +
  19 +%br
  20 +
  21 += link_to 'New Wiki', new_wiki_path
... ...
app/views/wikis/new.html.haml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +%h1 New wiki
  2 +
  3 += render 'form'
  4 +
  5 += link_to 'Back', wikis_path
... ...
app/views/wikis/show.html.haml 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +%p#notice= notice
  2 +
  3 +%h3= @wiki.title
  4 += @wiki.content
  5 +
  6 +%br
  7 += link_to 'Edit', edit_project_wiki_path(@project, @wiki)
... ...
config/routes.rb
1 1 Gitlab::Application.routes.draw do
2 2  
  3 +
3 4 # Optionally, enable Resque here
4 5 require 'resque/server'
5 6 mount Resque::Server.new, at: '/info/resque'
... ... @@ -55,6 +56,7 @@ Gitlab::Application.routes.draw do
55 56 get "files"
56 57 end
57 58  
  59 + resources :wikis, :only => [:show, :edit, :destroy]
58 60 resource :repository do
59 61 member do
60 62 get "branches"
... ...
db/migrate/20120216215008_create_wikis.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class CreateWikis < ActiveRecord::Migration
  2 + def change
  3 + create_table :wikis do |t|
  4 + t.string :title
  5 + t.text :content
  6 + t.integer :project_id
  7 +
  8 + t.timestamps
  9 + end
  10 + end
  11 +end
... ...
db/migrate/20120219130957_add_slug_to_wiki.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class AddSlugToWiki < ActiveRecord::Migration
  2 + def change
  3 + add_column :wikis, :slug, :string
  4 +
  5 + end
  6 +end
... ...
db/migrate/20120219140810_add_wiki_enabled_to_project.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class AddWikiEnabledToProject < ActiveRecord::Migration
  2 + def change
  3 + add_column :projects, :wiki_enabled, :boolean, :default => true, :null => false
  4 +
  5 + end
  6 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,11 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
  14 +<<<<<<< HEAD
14 15 ActiveRecord::Schema.define(:version => 20120216085842) do
  16 +=======
  17 +ActiveRecord::Schema.define(:version => 20120219140810) do
  18 +>>>>>>> wiki base sceleton
15 19  
16 20 create_table "issues", :force => true do |t|
17 21 t.string "title"
... ... @@ -80,6 +84,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120216085842) do
80 84 t.boolean "issues_enabled", :default => true, :null => false
81 85 t.boolean "wall_enabled", :default => true, :null => false
82 86 t.boolean "merge_requests_enabled", :default => true, :null => false
  87 + t.boolean "wiki_enabled", :default => true, :null => false
83 88 end
84 89  
85 90 create_table "protected_branches", :force => true do |t|
... ... @@ -158,4 +163,13 @@ ActiveRecord::Schema.define(:version =&gt; 20120216085842) do
158 163 t.datetime "updated_at"
159 164 end
160 165  
  166 + create_table "wikis", :force => true do |t|
  167 + t.string "title"
  168 + t.text "content"
  169 + t.integer "project_id"
  170 + t.datetime "created_at", :null => false
  171 + t.datetime "updated_at", :null => false
  172 + t.string "slug"
  173 + end
  174 +
161 175 end
... ...
spec/controllers/wikis_controller_spec.rb 0 → 100644
... ... @@ -0,0 +1,164 @@
  1 +require 'spec_helper'
  2 +
  3 +# This spec was generated by rspec-rails when you ran the scaffold generator.
  4 +# It demonstrates how one might use RSpec to specify the controller code that
  5 +# was generated by Rails when you ran the scaffold generator.
  6 +#
  7 +# It assumes that the implementation code is generated by the rails scaffold
  8 +# generator. If you are using any extension libraries to generate different
  9 +# controller code, this generated spec may or may not pass.
  10 +#
  11 +# It only uses APIs available in rails and/or rspec-rails. There are a number
  12 +# of tools you can use to make these specs even more expressive, but we're
  13 +# sticking to rails and rspec-rails APIs to keep things simple and stable.
  14 +#
  15 +# Compared to earlier versions of this generator, there is very limited use of
  16 +# stubs and message expectations in this spec. Stubs are only used when there
  17 +# is no simpler way to get a handle on the object needed for the example.
  18 +# Message expectations are only used when there is no simpler way to specify
  19 +# that an instance is receiving a specific message.
  20 +
  21 +describe WikisController do
  22 +
  23 + # This should return the minimal set of attributes required to create a valid
  24 + # Wiki. As you add validations to Wiki, be sure to
  25 + # update the return value of this method accordingly.
  26 + def valid_attributes
  27 + {}
  28 + end
  29 +
  30 + # This should return the minimal set of values that should be in the session
  31 + # in order to pass any filters (e.g. authentication) defined in
  32 + # WikisController. Be sure to keep this updated too.
  33 + def valid_session
  34 + {}
  35 + end
  36 +
  37 + describe "GET index" do
  38 + it "assigns all wikis as @wikis" do
  39 + wiki = Wiki.create! valid_attributes
  40 + get :index, {}, valid_session
  41 + assigns(:wikis).should eq([wiki])
  42 + end
  43 + end
  44 +
  45 + describe "GET show" do
  46 + it "assigns the requested wiki as @wiki" do
  47 + wiki = Wiki.create! valid_attributes
  48 + get :show, {:id => wiki.to_param}, valid_session
  49 + assigns(:wiki).should eq(wiki)
  50 + end
  51 + end
  52 +
  53 + describe "GET new" do
  54 + it "assigns a new wiki as @wiki" do
  55 + get :new, {}, valid_session
  56 + assigns(:wiki).should be_a_new(Wiki)
  57 + end
  58 + end
  59 +
  60 + describe "GET edit" do
  61 + it "assigns the requested wiki as @wiki" do
  62 + wiki = Wiki.create! valid_attributes
  63 + get :edit, {:id => wiki.to_param}, valid_session
  64 + assigns(:wiki).should eq(wiki)
  65 + end
  66 + end
  67 +
  68 + describe "POST create" do
  69 + describe "with valid params" do
  70 + it "creates a new Wiki" do
  71 + expect {
  72 + post :create, {:wiki => valid_attributes}, valid_session
  73 + }.to change(Wiki, :count).by(1)
  74 + end
  75 +
  76 + it "assigns a newly created wiki as @wiki" do
  77 + post :create, {:wiki => valid_attributes}, valid_session
  78 + assigns(:wiki).should be_a(Wiki)
  79 + assigns(:wiki).should be_persisted
  80 + end
  81 +
  82 + it "redirects to the created wiki" do
  83 + post :create, {:wiki => valid_attributes}, valid_session
  84 + response.should redirect_to(Wiki.last)
  85 + end
  86 + end
  87 +
  88 + describe "with invalid params" do
  89 + it "assigns a newly created but unsaved wiki as @wiki" do
  90 + # Trigger the behavior that occurs when invalid params are submitted
  91 + Wiki.any_instance.stub(:save).and_return(false)
  92 + post :create, {:wiki => {}}, valid_session
  93 + assigns(:wiki).should be_a_new(Wiki)
  94 + end
  95 +
  96 + it "re-renders the 'new' template" do
  97 + # Trigger the behavior that occurs when invalid params are submitted
  98 + Wiki.any_instance.stub(:save).and_return(false)
  99 + post :create, {:wiki => {}}, valid_session
  100 + response.should render_template("new")
  101 + end
  102 + end
  103 + end
  104 +
  105 + describe "PUT update" do
  106 + describe "with valid params" do
  107 + it "updates the requested wiki" do
  108 + wiki = Wiki.create! valid_attributes
  109 + # Assuming there are no other wikis in the database, this
  110 + # specifies that the Wiki created on the previous line
  111 + # receives the :update_attributes message with whatever params are
  112 + # submitted in the request.
  113 + Wiki.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
  114 + put :update, {:id => wiki.to_param, :wiki => {'these' => 'params'}}, valid_session
  115 + end
  116 +
  117 + it "assigns the requested wiki as @wiki" do
  118 + wiki = Wiki.create! valid_attributes
  119 + put :update, {:id => wiki.to_param, :wiki => valid_attributes}, valid_session
  120 + assigns(:wiki).should eq(wiki)
  121 + end
  122 +
  123 + it "redirects to the wiki" do
  124 + wiki = Wiki.create! valid_attributes
  125 + put :update, {:id => wiki.to_param, :wiki => valid_attributes}, valid_session
  126 + response.should redirect_to(wiki)
  127 + end
  128 + end
  129 +
  130 + describe "with invalid params" do
  131 + it "assigns the wiki as @wiki" do
  132 + wiki = Wiki.create! valid_attributes
  133 + # Trigger the behavior that occurs when invalid params are submitted
  134 + Wiki.any_instance.stub(:save).and_return(false)
  135 + put :update, {:id => wiki.to_param, :wiki => {}}, valid_session
  136 + assigns(:wiki).should eq(wiki)
  137 + end
  138 +
  139 + it "re-renders the 'edit' template" do
  140 + wiki = Wiki.create! valid_attributes
  141 + # Trigger the behavior that occurs when invalid params are submitted
  142 + Wiki.any_instance.stub(:save).and_return(false)
  143 + put :update, {:id => wiki.to_param, :wiki => {}}, valid_session
  144 + response.should render_template("edit")
  145 + end
  146 + end
  147 + end
  148 +
  149 + describe "DELETE destroy" do
  150 + it "destroys the requested wiki" do
  151 + wiki = Wiki.create! valid_attributes
  152 + expect {
  153 + delete :destroy, {:id => wiki.to_param}, valid_session
  154 + }.to change(Wiki, :count).by(-1)
  155 + end
  156 +
  157 + it "redirects to the wikis list" do
  158 + wiki = Wiki.create! valid_attributes
  159 + delete :destroy, {:id => wiki.to_param}, valid_session
  160 + response.should redirect_to(wikis_url)
  161 + end
  162 + end
  163 +
  164 +end
... ...
spec/views/wikis/edit.html.haml_spec.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "wikis/edit" do
  4 + before(:each) do
  5 + @wiki = assign(:wiki, stub_model(Wiki,
  6 + :title => "MyString",
  7 + :content => "MyText"
  8 + ))
  9 + end
  10 +
  11 + it "renders the edit wiki form" do
  12 + render
  13 +
  14 + # Run the generator again with the --webrat flag if you want to use webrat matchers
  15 + assert_select "form", :action => wikis_path(@wiki), :method => "post" do
  16 + assert_select "input#wiki_title", :name => "wiki[title]"
  17 + assert_select "textarea#wiki_content", :name => "wiki[content]"
  18 + end
  19 + end
  20 +end
... ...
spec/views/wikis/index.html.haml_spec.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "wikis/index" do
  4 + before(:each) do
  5 + assign(:wikis, [
  6 + stub_model(Wiki,
  7 + :title => "Title",
  8 + :content => "MyText"
  9 + ),
  10 + stub_model(Wiki,
  11 + :title => "Title",
  12 + :content => "MyText"
  13 + )
  14 + ])
  15 + end
  16 +
  17 + it "renders a list of wikis" do
  18 + render
  19 + # Run the generator again with the --webrat flag if you want to use webrat matchers
  20 + assert_select "tr>td", :text => "Title".to_s, :count => 2
  21 + # Run the generator again with the --webrat flag if you want to use webrat matchers
  22 + assert_select "tr>td", :text => "MyText".to_s, :count => 2
  23 + end
  24 +end
... ...
spec/views/wikis/new.html.haml_spec.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "wikis/new" do
  4 + before(:each) do
  5 + assign(:wiki, stub_model(Wiki,
  6 + :title => "MyString",
  7 + :content => "MyText"
  8 + ).as_new_record)
  9 + end
  10 +
  11 + it "renders new wiki form" do
  12 + render
  13 +
  14 + # Run the generator again with the --webrat flag if you want to use webrat matchers
  15 + assert_select "form", :action => wikis_path, :method => "post" do
  16 + assert_select "input#wiki_title", :name => "wiki[title]"
  17 + assert_select "textarea#wiki_content", :name => "wiki[content]"
  18 + end
  19 + end
  20 +end
... ...
spec/views/wikis/show.html.haml_spec.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "wikis/show" do
  4 + before(:each) do
  5 + @wiki = assign(:wiki, stub_model(Wiki,
  6 + :title => "Title",
  7 + :content => "MyText"
  8 + ))
  9 + end
  10 +
  11 + it "renders attributes in <p>" do
  12 + render
  13 + # Run the generator again with the --webrat flag if you want to use webrat matchers
  14 + rendered.should match(/Title/)
  15 + # Run the generator again with the --webrat flag if you want to use webrat matchers
  16 + rendered.should match(/MyText/)
  17 + end
  18 +end
... ...