Commit 621bfdb4aa6c5ef2b031f7c4fb7753eb80d7a5b5

Authored by vsizov
1 parent 49d58492

wiki: rspec

@@ -159,20 +159,6 @@ ActiveRecord::Schema.define(:version => 20120219193300) do @@ -159,20 +159,6 @@ ActiveRecord::Schema.define(:version => 20120219193300) do
159 t.datetime "updated_at" 159 t.datetime "updated_at"
160 end 160 end
161 161
162 - create_table "wiki_pages", :force => true do |t|  
163 - t.string "slug"  
164 - t.string "title"  
165 - t.text "content"  
166 - t.integer "author_id"  
167 - t.integer "project_id"  
168 - t.datetime "created_at"  
169 - t.datetime "updated_at"  
170 - end  
171 -  
172 - add_index "wiki_pages", ["author_id"], :name => "index_wiki_pages_on_author_id"  
173 - add_index "wiki_pages", ["project_id"], :name => "index_wiki_pages_on_project_id"  
174 - add_index "wiki_pages", ["slug"], :name => "index_wiki_pages_on_slug", :unique => true  
175 -  
176 create_table "wikis", :force => true do |t| 162 create_table "wikis", :force => true do |t|
177 t.string "title" 163 t.string "title"
178 t.text "content" 164 t.text "content"
spec/controllers/wikis_controller_spec.rb
@@ -1,164 +0,0 @@ @@ -1,164 +0,0 @@
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/factories.rb
@@ -59,3 +59,8 @@ end @@ -59,3 +59,8 @@ end
59 Factory.add(:web_hook, WebHook) do |obj| 59 Factory.add(:web_hook, WebHook) do |obj|
60 obj.url = Faker::Internet.url 60 obj.url = Faker::Internet.url
61 end 61 end
  62 +
  63 +Factory.add(:wikis, WebHook) do |obj|
  64 + obj.title = Faker::Lorem.sentence
  65 + obj.content = Faker::Lorem.sentence
  66 +end
spec/requests/wikis_spec.rb 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "Wiki" do
  4 + let(:project) { Factory :project }
  5 +
  6 + before do
  7 + login_as :user
  8 + project.add_access(@user, :read, :write)
  9 + end
  10 +
  11 + describe "Add pages" do
  12 + before do
  13 + visit project_wiki_path(project, :index)
  14 + end
  15 +
  16 + it "should see form" do
  17 + page.should have_content("Editing page")
  18 + end
  19 +
  20 + it "should see added page" do
  21 + fill_in "Title", :with => 'Test title'
  22 + fill_in "Content", :with => '[link test](test)'
  23 + click_on "Save"
  24 +
  25 + page.should have_content("Test title")
  26 + page.should have_content("link test")
  27 +
  28 + click_link "link test"
  29 +
  30 + page.should have_content("Editing page")
  31 + end
  32 +
  33 + end
  34 +
  35 +end
spec/views/wikis/edit.html.haml_spec.rb
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
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
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
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
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
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
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
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