Skip to content

Commit e173a46

Browse files
committed
Merge pull request #76 from dominic/rails3
Question creation and refactoring
2 parents cc95348 + 86a79c8 commit e173a46

43 files changed

Lines changed: 364 additions & 126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ group :development, :test do
3636
gem 'fabrication'
3737
gem 'rspec-rails'
3838
gem 'cucumber-rails'
39+
gem "faker"
40+
end
41+
42+
group :test do
43+
gem "mocha"
44+
gem "database_cleaner"
3945
end
40-
gem "mocha", :group => :test

Gemfile.lock

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ GEM
6868
capybara (>= 1.0.0)
6969
cucumber (~> 1.0.0)
7070
nokogiri (>= 1.4.6)
71+
database_cleaner (0.6.7)
7172
devise (1.4.2)
7273
bcrypt-ruby (~> 2.1.2)
7374
orm_adapter (~> 0.0.3)
@@ -77,6 +78,8 @@ GEM
7778
execjs (1.2.4)
7879
multi_json (~> 1.0)
7980
fabrication (1.1.0)
81+
faker (0.9.5)
82+
i18n (~> 0.4)
8083
ffi (1.0.9)
8184
gherkin (2.4.16)
8285
json (>= 1.4.6)
@@ -149,17 +152,19 @@ GEM
149152
rake (0.9.2)
150153
rdoc (3.9.4)
151154
responders (0.6.4)
152-
rspec (2.0.0.beta.19)
153-
rspec-core (= 2.0.0.beta.19)
154-
rspec-expectations (= 2.0.0.beta.19)
155-
rspec-mocks (= 2.0.0.beta.19)
156-
rspec-core (2.0.0.beta.19)
157-
rspec-expectations (2.0.0.beta.19)
158-
diff-lcs (>= 1.1.2)
159-
rspec-mocks (2.0.0.beta.19)
160-
rspec-rails (2.0.0.beta.19)
161-
rspec (= 2.0.0.beta.19)
162-
webrat (>= 0.7.2.beta.1)
155+
rspec (2.6.0)
156+
rspec-core (~> 2.6.0)
157+
rspec-expectations (~> 2.6.0)
158+
rspec-mocks (~> 2.6.0)
159+
rspec-core (2.6.4)
160+
rspec-expectations (2.6.0)
161+
diff-lcs (~> 1.1.2)
162+
rspec-mocks (2.6.0)
163+
rspec-rails (2.6.1)
164+
actionpack (~> 3.0)
165+
activesupport (~> 3.0)
166+
railties (~> 3.0)
167+
rspec (~> 2.6.0)
163168
rubyzip (0.9.4)
164169
sass (3.1.7)
165170
sass-rails (3.1.0.rc.6)
@@ -195,10 +200,6 @@ GEM
195200
raindrops (~> 0.6)
196201
warden (1.0.5)
197202
rack (>= 1.0)
198-
webrat (0.7.3)
199-
nokogiri (>= 1.2.0)
200-
rack (>= 1.0)
201-
rack-test (>= 0.5.3)
202203
xpath (0.1.4)
203204
nokogiri (~> 1.3)
204205

@@ -210,8 +211,10 @@ DEPENDENCIES
210211
cancan
211212
coffee-rails (~> 3.1.0.rc)
212213
cucumber-rails
214+
database_cleaner
213215
devise (>= 1.2)
214216
fabrication
217+
faker
215218
haml-rails
216219
inherited_resources
217220
jnunemaker-validatable (>= 1.8.4)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.flash{
2+
color: red;
3+
padding: 2px;
4+
font-size: 12x;
5+
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
// Place all the styles related to the Questions controller here.
22
// They will automatically be included in application.css.
33
// You can use Sass (SCSS) here: http://sass-lang.com/
4-
.flash{
5-
color: red;
6-
padding: 2px;
7-
font-size: 12x;
8-
}

app/assets/stylesheets/scaffolds.css.scss

Whitespace-only changes.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
class QuestionsController < InheritedController
2-
3-
def index
4-
@question = Question.new
5-
end
2+
load_and_authorize_resource
63

74
def create
8-
create!(:notice => "Question Asked!"){collection_url}
5+
@question = Question.create params[:question]
6+
@question.user = current_user
7+
create!(:notice => "Question Asked!"){ collection_url }
98
end
109
end

app/models/ability.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
class Ability
22
include CanCan::Ability
33

4-
def initialize(user)
4+
def initialize(user)
5+
6+
can :read, Question
7+
8+
if user
9+
can :create, Question
10+
can :manage, Question, :user => user
11+
end
12+
513
# Define abilities for the passed in user here. For example:
614
#
715
# user ||= User.new # guest user (not logged in)

app/models/question.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ class Question
44
key :title, String
55
key :description, String
66

7+
belongs_to :user
8+
79
end

app/models/user.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class User
55
devise :database_authenticatable, :registerable,
66
:recoverable, :rememberable, :trackable, :validatable
77

8-
8+
key :username, String
9+
key :email, String
910

1011
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h2>Resend confirmation instructions</h2>
2+
3+
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= f.error_notification %>
5+
6+
<div class="inputs">
7+
<%= f.input :email, :required => true %>
8+
</div>
9+
10+
<div class="actions">
11+
<%= f.button :submit, "Resend confirmation instructions" %>
12+
</div>
13+
<% end %>
14+
15+
<%= render :partial => "devise/shared/links" %>

0 commit comments

Comments
 (0)