diff --git a/Gemfile b/Gemfile index 6ee71f38..020c622f 100644 --- a/Gemfile +++ b/Gemfile @@ -36,5 +36,10 @@ group :development, :test do gem 'fabrication' gem 'rspec-rails' gem 'cucumber-rails' + gem "faker" +end + +group :test do + gem "mocha" + gem "database_cleaner" end -gem "mocha", :group => :test diff --git a/Gemfile.lock b/Gemfile.lock index 7bc1c012..85b2c9bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM capybara (>= 1.0.0) cucumber (~> 1.0.0) nokogiri (>= 1.4.6) + database_cleaner (0.6.7) devise (1.4.2) bcrypt-ruby (~> 2.1.2) orm_adapter (~> 0.0.3) @@ -77,6 +78,8 @@ GEM execjs (1.2.4) multi_json (~> 1.0) fabrication (1.1.0) + faker (0.9.5) + i18n (~> 0.4) ffi (1.0.9) gherkin (2.4.16) json (>= 1.4.6) @@ -149,17 +152,19 @@ GEM rake (0.9.2) rdoc (3.9.4) responders (0.6.4) - rspec (2.0.0.beta.19) - rspec-core (= 2.0.0.beta.19) - rspec-expectations (= 2.0.0.beta.19) - rspec-mocks (= 2.0.0.beta.19) - rspec-core (2.0.0.beta.19) - rspec-expectations (2.0.0.beta.19) - diff-lcs (>= 1.1.2) - rspec-mocks (2.0.0.beta.19) - rspec-rails (2.0.0.beta.19) - rspec (= 2.0.0.beta.19) - webrat (>= 0.7.2.beta.1) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) + rspec-rails (2.6.1) + actionpack (~> 3.0) + activesupport (~> 3.0) + railties (~> 3.0) + rspec (~> 2.6.0) rubyzip (0.9.4) sass (3.1.7) sass-rails (3.1.0.rc.6) @@ -195,10 +200,6 @@ GEM raindrops (~> 0.6) warden (1.0.5) rack (>= 1.0) - webrat (0.7.3) - nokogiri (>= 1.2.0) - rack (>= 1.0) - rack-test (>= 0.5.3) xpath (0.1.4) nokogiri (~> 1.3) @@ -210,8 +211,10 @@ DEPENDENCIES cancan coffee-rails (~> 3.1.0.rc) cucumber-rails + database_cleaner devise (>= 1.2) fabrication + faker haml-rails inherited_resources jnunemaker-validatable (>= 1.8.4) diff --git a/app/assets/stylesheets/layout.css.scss b/app/assets/stylesheets/layout.css.scss new file mode 100644 index 00000000..bb49fa9d --- /dev/null +++ b/app/assets/stylesheets/layout.css.scss @@ -0,0 +1,5 @@ +.flash{ + color: red; + padding: 2px; + font-size: 12x; +} \ No newline at end of file diff --git a/app/assets/stylesheets/questions.css.scss b/app/assets/stylesheets/questions.css.scss index 096dd68f..a7cd45c1 100644 --- a/app/assets/stylesheets/questions.css.scss +++ b/app/assets/stylesheets/questions.css.scss @@ -1,8 +1,3 @@ // Place all the styles related to the Questions controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.flash{ - color: red; - padding: 2px; - font-size: 12x; -} diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss deleted file mode 100644 index e69de29b..00000000 diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index a45f4d1d..bdd2ca6d 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -1,10 +1,9 @@ class QuestionsController < InheritedController - - def index - @question = Question.new - end + load_and_authorize_resource def create - create!(:notice => "Question Asked!"){collection_url} + @question = Question.create params[:question] + @question.user = current_user + create!(:notice => "Question Asked!"){ collection_url } end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 58929d7a..d3a0a9c8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,7 +1,15 @@ class Ability include CanCan::Ability - def initialize(user) + def initialize(user) + + can :read, Question + + if user + can :create, Question + can :manage, Question, :user => user + end + # Define abilities for the passed in user here. For example: # # user ||= User.new # guest user (not logged in) diff --git a/app/models/question.rb b/app/models/question.rb index 488344ba..811d372f 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -4,4 +4,6 @@ class Question key :title, String key :description, String + belongs_to :user + end diff --git a/app/models/user.rb b/app/models/user.rb index 8dbe1d3a..ca6dc71c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,6 +5,7 @@ class User devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - + key :username, String + key :email, String end diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 00000000..9b0344e8 --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,15 @@ +

Resend confirmation instructions

+ +<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, :required => true %> +
+ +
+ <%= f.button :submit, "Resend confirmation instructions" %> +
+<% end %> + +<%= render :partial => "devise/shared/links" %> \ No newline at end of file diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..a6ea8ca1 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @resource.email %>!

+ +

You can confirm your account through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..ae9e888a --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password, and you can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..2263c219 --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive amount of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>

diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 00000000..be56ee41 --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,19 @@ +

Change your password

+ +<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %> + <%= f.error_notification %> + + <%= f.input :reset_password_token, :as => :hidden %> + <%= f.full_error :reset_password_token %> + +
+ <%= f.input :password, :label => "New password", :required => true %> + <%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %> +
+ +
+ <%= f.button :submit, "Change my password" %> +
+<% end %> + +<%= render :partial => "devise/shared/links" %> \ No newline at end of file diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 00000000..56e2906f --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,15 @@ +

Forgot your password?

+ +<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, :required => true %> +
+ +
+ <%= f.button :submit, "Send me reset password instructions" %> +
+<% end %> + +<%= render :partial => "devise/shared/links" %> \ No newline at end of file diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 00000000..a093f1b6 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,23 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :username, :autofocus => true %> + <%= f.input :email, :autofocus => true %> + <%= f.input :password, :hint => "leave it blank if you don't want to change it", :required => false %> + <%= f.input :password_confirmation, :required => false %> + <%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %> +
+ +
+ <%= f.button :submit, "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 00000000..0fea2aaa --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,18 @@ +

Sign up

+ +<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :username, :autofocus => true %> + <%= f.input :email %> + <%= f.input :password %> + <%= f.input :password_confirmation %> +
+ +
+ <%= f.button :submit, "Sign up" %> +
+<% end %> + +<%= render :partial => "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 00000000..ce5495c6 --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,15 @@ +

Sign in

+ +<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> +
+ <%= f.input :username, :required => false, :autofocus => true %> + <%= f.input :password, :required => false %> + <%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %> +
+ +
+ <%= f.button :submit, "Sign in" %> +
+<% end %> + +<%= render :partial => "devise/shared/links" %> \ No newline at end of file diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb new file mode 100644 index 00000000..eab783a4 --- /dev/null +++ b/app/views/devise/shared/_links.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Sign in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> \ No newline at end of file diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 00000000..89011af0 --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,15 @@ +

Resend unlock instructions

+ +<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :email, :required => true %> +
+ +
+ <%= f.button :submit, "Resend unlock instructions" %> +
+<% end %> + +<%= render :partial => "devise/shared/links" %> \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1c83dab3..25971649 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -8,5 +8,13 @@ = csrf_meta_tags %body = render "shared/menu/user" - .flash #{flash[:notice]} + = render "shared/menu/main" + + - if flash[:notice] + .flash #{flash[:notice]} + + %h1.title + = yield :title + + = yield :links = yield diff --git a/app/views/questions/edit.html.haml b/app/views/questions/edit.html.haml index e05dd7e9..76006cdd 100644 --- a/app/views/questions/edit.html.haml +++ b/app/views/questions/edit.html.haml @@ -1,4 +1,4 @@ - content_for :title do - = "Editing #{resource}" + = "Editing #{resource.title}" = render 'form' diff --git a/app/views/questions/index.html.haml b/app/views/questions/index.html.haml index b33251a4..e8e459f4 100644 --- a/app/views/questions/index.html.haml +++ b/app/views/questions/index.html.haml @@ -1,17 +1,9 @@ -:javascript - $(document).ready(function(){ - $('#ask_button').click( - function(){ - $('#the_form').show(); - $('#ask_button').remove(); - }); - }); - content_for :title do Questions - content_for :links do - if can? :create, Question - = link_to "New question", new_resource_path + = link_to "Ask a Question", new_resource_path %table %thead @@ -23,7 +15,3 @@ %th = render :partial => "list", :collection => collection -%div#the_form{:style=>'display:none'} - = render "form" -- if current_user - %h3#ask_button Ask a question diff --git a/app/views/questions/show.html.haml b/app/views/questions/show.html.haml index 100e977c..a17f6f9a 100644 --- a/app/views/questions/show.html.haml +++ b/app/views/questions/show.html.haml @@ -1,5 +1,5 @@ - content_for :title do - = resource + = resource.title - content_for :links do - if can? :update, resource @@ -7,8 +7,8 @@ - if can? :destroy, resource = link_to 'Delete', resource_path, :confirm => 'Are you sure?', :method => :delete -%dl - %dt Title - %dd= resource.title - %dt Description - %dd= resource.description +- if resource.user + .author Created by #{resource.user.username} + +.description + = resource.description diff --git a/app/views/shared/menu/_main.html.haml b/app/views/shared/menu/_main.html.haml new file mode 100644 index 00000000..8ac67158 --- /dev/null +++ b/app/views/shared/menu/_main.html.haml @@ -0,0 +1,3 @@ += semantic_menu do |root| + - root.add "Home", root_path + - root.add "Questions", questions_path \ No newline at end of file diff --git a/app/views/shared/menu/_user.html.haml b/app/views/shared/menu/_user.html.haml index 0a73210f..e2502ea8 100644 --- a/app/views/shared/menu/_user.html.haml +++ b/app/views/shared/menu/_user.html.haml @@ -1,6 +1,6 @@ = semantic_menu do |root| - if current_user - = current_user.email - - root.add "Log Out", destroy_user_session_path, :method => :delete + = current_user.username + - root.add "Log Out", logout_path - else - - root.add "Log In", new_user_session_path \ No newline at end of file + - root.add "Log In", login_path \ No newline at end of file diff --git a/app/views/static/root.html.haml b/app/views/static/root.html.haml index dc2fc6a3..7430f255 100644 --- a/app/views/static/root.html.haml +++ b/app/views/static/root.html.haml @@ -1,2 +1 @@ %h1 Home! -%a(href="/questions") Q&A diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 9537ef27..de1df448 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -22,7 +22,7 @@ # session. If you need permissions, you should implement that in a before filter. # You can also supply a hash where the value is a boolean determining whether # or not authentication should be aborted when the value is not present. - # config.authentication_keys = [ :email ] + config.authentication_keys = [ :username ] # Configure parameters from the request object used for authentication. Each entry # given should be a request method and it will automatically be passed to the @@ -34,12 +34,12 @@ # Configure which authentication keys should be case-insensitive. # These keys will be downcased upon creating or modifying a user and when used # to authenticate or find a user. Default is :email. - config.case_insensitive_keys = [ :email ] + config.case_insensitive_keys = [ :email, :username ] # Configure which authentication keys should have whitespace stripped. # These keys will have whitespace before and after removed upon creating or # modifying a user and when used to authenticate or find a user. Default is :email. - config.strip_whitespace_keys = [ :email ] + config.strip_whitespace_keys = [ :email, :username ] # Tell if authentication through request.params is enabled. True by default. # config.params_authenticatable = true diff --git a/config/routes.rb b/config/routes.rb index 32c6a422..0d403fad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,10 @@ end end - devise_for :users + devise_for :users do + get "login" => "devise/sessions#new", :as => "login" + get "logout" => "devise/sessions#destroy", :as => "logout" + end root :to => "static#root" diff --git a/db/schema.rb b/db/schema.rb index af286d41..b5e6a796 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,6 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110830001940) do - - create_table "questions", :force => true do |t| - t.string "title" - t.text "description" - t.integer "user_id" - t.datetime "created_at" - t.datetime "updated_at" - end +ActiveRecord::Schema.define(:version => 0) do end diff --git a/db/seeds.rb b/db/seeds.rb deleted file mode 100644 index 8c7ab0c1..00000000 --- a/db/seeds.rb +++ /dev/null @@ -1,17 +0,0 @@ -# Drop all the old Rels - -Rel.all.each{|r| r.destroy} - -#Make our standard ones -Rel.create :slug => "current-application-version", - :description => "The linked resource describes the most recently released version of the desktop application." -Rel.create :slug => "rel-index", - :description => "This relation is the root resource for rels. It contains the list of all rels we've defined." -Rel.create :slug => "rel", - :description => "This relation is a link to a rel resource." -Rel.create :slug => "program-index", - :description => "This relation is the root resource for programs. It contains the list of all programs." -Rel.create :slug => "program", - :description => "This relation is a link to a program resource." -Rel.create :slug => "program-new", - :description => "This relation is a link to a form that will allow you to make a program resource." diff --git a/features/questions.feature b/features/questions.feature new file mode 100644 index 00000000..83247a3d --- /dev/null +++ b/features/questions.feature @@ -0,0 +1,22 @@ +Feature: CRUD actions for question + + As a user of the site, I can perform standard CRUD actions on questions + + Background: I am logged into the site + Given I am a user with username "test" and password "password" + And I sign in as "test/password" + And I am on the questions index + + Scenario: Create a question + When I follow "Ask a Question" + And I fill in the following: + | Title | My Question | + | Description | My Description | + And I press "Ask Everyone" + Then I should see "Question Asked!" + When I follow "Show" within "table" + Then I should see "My Question" within ".title" + And I should see "Created by test" + + Scenario: Edit an existing question + Given I have created a question \ No newline at end of file diff --git a/features/step_definitions/question_steps.rb b/features/step_definitions/question_steps.rb new file mode 100644 index 00000000..445a20d6 --- /dev/null +++ b/features/step_definitions/question_steps.rb @@ -0,0 +1,3 @@ +Given /^I have created a question$/ do + pending +end \ No newline at end of file diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb new file mode 100644 index 00000000..86682c34 --- /dev/null +++ b/features/step_definitions/user_steps.rb @@ -0,0 +1,60 @@ +Given /^no user exists with an email of "(.*)"$/ do |email| + User.find(:first, :conditions => { :email => email }).should be_nil +end + +Given /^I am a user with username "([^"]*)" and password "([^"]*)"$/ do |username, password| + User.new(:username => username, + :email => "#{username}@example.com", + :password => password, + :password_confirmation => password).save! +end + +Then /^I should be already signed in$/ do + And %{I should see "Logout"} +end + +Given /^I am signed up as "(.*)\/(.*)"$/ do |username, password| + Given %{I am not logged in} + When %{I go to the sign up page} + And %{I fill in "Username" with "#{username}"} + And %{I fill in "Email" with "#{username}@example.com"} + And %{I fill in "Password" with "#{password}"} + And %{I fill in "Password confirmation" with "#{password}"} + And %{I press "Sign up"} + Then %{I should see "You have signed up successfully. If enabled, a confirmation was sent to your e-mail."} + And %{I am logout} +end + +Then /^I sign out$/ do + visit(logout_path) +end + +Given /^I am logout$/ do + Given %{I sign out} +end + +Given /^I am not logged in$/ do + Given %{I sign out} +end + +When /^I sign in as "(.*)\/(.*)"$/ do |username, password| + Given %{I am not logged in} + When %{I go to the sign in page} + And %{I fill in "Username" with "#{username}"} + And %{I fill in "Password" with "#{password}"} + And %{I press "Sign in"} +end + +Then /^I should be signed in$/ do + Then %{I should see "Signed in successfully."} +end + +When /^I return next time$/ do + And %{I go to the home page} +end + +Then /^I should be signed out$/ do + And %{I should see "Sign up"} + And %{I should see "Login"} + And %{I should not see "Logout"} +end diff --git a/features/support/env.rb b/features/support/env.rb index 6c40c8f1..3809374e 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -31,10 +31,14 @@ # Remove/comment out the lines below if your app doesn't have a database. # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. -begin - DatabaseCleaner.strategy = :transaction -rescue NameError - raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." +DatabaseCleaner.strategy = :truncation + +Before do + MongoMapper.database.collections.each do |collection| + unless collection.name.match(/^system\./) + collection.remove + end + end end # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. diff --git a/features/support/paths.rb b/features/support/paths.rb index ee9b251e..75be8ead 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -11,6 +11,13 @@ def path_to(page_name) when /^the home\s?page$/ '/' + when /^the sign in page$/ + login_path + + when /^the questions index$/ + questions_path + + # Add more mappings here. # Here is an example that pulls values out of the Regexp: # diff --git a/spec/fabricators/question_fabricator.rb b/spec/fabricators/question_fabricator.rb index 600c15ba..5870e67e 100644 --- a/spec/fabricators/question_fabricator.rb +++ b/spec/fabricators/question_fabricator.rb @@ -1,4 +1,5 @@ Fabricator(:question) do - title "MyString" - description "MyString" + title "Title" + description "Description" + user end diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 2c5f8815..b50a01bb 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -1,2 +1,5 @@ Fabricator(:user) do + email { sequence(:email) { |i| "user#{i}@example.com"} } + password "password" + password_confirmation "password" end diff --git a/spec/requests/api/api_programs_spec.rb b/spec/requests/api/api_programs_spec.rb deleted file mode 100644 index fd3b5185..00000000 --- a/spec/requests/api/api_programs_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe "Api::Programs" do - describe "GET /api_programs" do - it "works! (now write some real specs)" do - # Run the generator again with the --webrat flag if you want to use webrat methods/matchers - get api_programs_path - response.status.should be(200) - end - end -end diff --git a/spec/requests/questions_spec.rb b/spec/requests/questions_spec.rb deleted file mode 100644 index 528b2cd5..00000000 --- a/spec/requests/questions_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe "Questions" do - describe "GET /questions" do - it "works! (now write some real specs)" do - # Run the generator again with the --webrat flag if you want to use webrat methods/matchers - get questions_path - response.status.should be(200) - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1e810ec7..4cbb17f5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,11 +17,17 @@ # config.mock_with :rr config.mock_with :rspec - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - # config.fixture_path = "#{::Rails.root}/spec/fixtures" - # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. # config.use_transactional_fixtures = true + + config.after(:each) do + MongoMapper.database.collections.each do |collection| + unless collection.name.match(/^system\./) + collection.remove + end + end + end end + diff --git a/spec/views/questions/index.html.haml_spec.rb b/spec/views/questions/index.html.haml_spec.rb index 41a898ff..9c4c65e5 100644 --- a/spec/views/questions/index.html.haml_spec.rb +++ b/spec/views/questions/index.html.haml_spec.rb @@ -2,16 +2,11 @@ describe "questions/index.html.haml" do before(:each) do - assign(:questions, [ - stub_model(Question, - :title => "Title", - :description => "Description" - ), - stub_model(Question, - :title => "Title", - :description => "Description" - ) - ]) + questions = [] + 2.times do + questions = Fabricate(:question) + end + assign("collection", questions) end it "renders a list of questions" do diff --git a/spec/views/root.html.haml_spec.rb b/spec/views/root.html.haml_spec.rb index eb442806..de25318e 100644 --- a/spec/views/root.html.haml_spec.rb +++ b/spec/views/root.html.haml_spec.rb @@ -2,9 +2,9 @@ describe "static/root" do - it "links to questions" do + it "has homepage content" do render - rendered.should have_selector('a', :href => '/questions') + rendered.should have_selector('h1', :content => "Home!") end end