How to setup factory_girl_rails with Rails 5.0.1 - factory-bot

I just setup a new Rails project with Rails 5.0.1
I added factory_girl_rails to the development and test group in the Gemfile.
Then I created a article factory in the spec/factories folder:
FactoryGirl.define do
factory :article do
title { Faker::Lorem.sentence }
body { Faker::Lorem.paragraph }
end
end
my feature spec looks like this:
require 'rails_helper'
feature "guest views articles" do
let(:article1) { FactoryGirl.create(article) }
let(:article2) { FactoryGirl.create(article) }
scenario "by visiting index page" do
visit articles_path
expect(page).to have_content article1.title
expect(page).to have_content article2.title
end
end
However, when I run the spec, I get this error message:
Failures:
1) guest views articles by visiting index page
Failure/Error: let(:article1) { FactoryGirl.create(article) }
NameError:
undefined local variable or method `article' for # <RSpec::ExampleGroups::GuestViewsArticles:0x007fe957fad078>
Did you mean? article2
article1
# ./spec/features/guest_views_articles_spec.rb:5:in `block (2 levels) in <top (required)>'
# ./spec/features/guest_views_articles_spec.rb:10:in `block (2 levels) in <top (required)>'
from the error message, it seems like the article factory is not defined or recognized. Did I forgot something when setting up the article factory?
my repository is at:
https://github.com/acandael/personalsite/tree/first_test
thanks for your help,
Anthony

found the issue:
let(:article1) { FactoryGirl.create(article) }
has to be
let(:article1) { FactoryGirl.create(:article) }

Related

pod lock file not generating all the dependencies are downloading in flutter

getting this error while pod install
NoMethodError - undefined method `=~' for [["PICKER_MEDIA=1"], ["PICKER_AUDIO=1"], ["PICKER_DOCUMENT=1"]]:Array
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:446:in block (2 levels) in merged_xcconfigs' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:446:in all?'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:446:in block in merged_xcconfigs' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:444:in each'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:444:in each_with_object' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:444:in merged_xcconfigs'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:1057:in block in <class:PodTargetSettings>' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:120:in block in define_build_settings_method'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:177:in block in remove_pod_target_xcconfig_overrides_from_target' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:174:in each'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:174:in remove_pod_target_xcconfig_overrides_from_target' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:157:in block in add_target'
internal:kernel:90:in tap' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:156:in add_target'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:47:in block in install!' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in message'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb:40:in install!' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:115:in block in install_pod_targets'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:112:in map' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator.rb:112:in install_pod_targets'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/single_pods_project_generator.rb:32:in block in install_all_pod_targets' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in message'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/single_pods_project_generator.rb:31:in install_all_pod_targets' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/single_pods_project_generator.rb:19:in generate!'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:314:in block in create_and_save_projects' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in section'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:309:in create_and_save_projects' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:301:in generate_pods_project'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:180:in integrate' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:167:in install!'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/command/update.rb:63:in run' /usr/local/lib/ruby/gems/3.2.0/gems/claide-1.1.0/lib/claide/command.rb:334:in run'
/usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in run' /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.11.3/bin/pod:55:in <top (required)>'
/usr/local/bin/pod:25:in load' /usr/local/bin/pod:25:in '
Try this it'll solve the issue
I got the same issue in this file gems/3.2.0/gems/cocoapods-1.11.3/lib/cocoapods/target/build_settings.rb:446:in `block (2 levels) in merged_xcconfigs' installing with gem
ruby 3.2.0
replacing "=~" by "==" seems to work but no idea if it has side effects I am just using this thing

Failing Rails 4 controller test - ActiveRecord::AssociationTypeMismatch?

I'm building a Rails (4.1.8) application with Postgres (0.18.3), Rspec (3.1.0), and FactoryGirl (4.5.0). I need help troubleshooting a controller test, which is throwing an Active Record::AssociationTypeMismatch error caused by a FactoryGirl object.
Here's my Fitness goals controller index action:
def index
#fitness_goals = #member.fitness_goals.order(:start_date)
end
This is my set-up and test of the fitness goals controller index action (fitness_goals_controller_spec.rb):
RSpec.describe FitnessGoalsController, :type => :controller do
let(:member_attributes) { {
"first_name" => 'Joe',
"last_name" => 'Smith',
"sex" => 'Male',
"age" => 30,
"height" => 69,
"weight" => 187,
"goal" => ["Lose Fat"],
"start_date" => Date.current
}
}
before :each do
#request.env["devise.mapping"] = Devise.mappings[:user]
#user = FactoryGirl.create(:user)
sign_in #user
#member = #user.build_member member_attributes
#member.save
#fitness_goal = FactoryGirl.create(:fitness_goal, member: #member)
#fitness_goal_attributes = FactoryGirl.build(:fitness_goal).attributes
#fitness_goal_invalid_attributes = FactoryGirl.build(:fitness_goal, timeframe_id: nil).attributes
#fitness_goal_update_attributes = FactoryGirl.build(:fitness_goal).attributes
#fitness_goal_update_invalid_attributes = FactoryGirl.build(:fitness_goal, timeframe_id: nil).attributes
end
describe "GET index" do
it "assigns all fitness goals as #member.fitness_goals" do
get :index, { :member_id => #member }
expect(assigns(:fitness_goals)).to eq(#member.reload.fitness_goals)
end
end
The rspec error and backtrace:
1) FitnessGoalsController GET index assigns all fitness goals as #member.fitness_goals
Failure/Error: #fitness_goal = FactoryGirl.create(:fitness_goal, member: #member)
ActiveRecord::AssociationTypeMismatch:
Target(#62887900) expected, got String(#8489780)
# .rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/associations/association.rb:216:in `raise_on_type_mismatch!'
# .rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/associations/collection_association.rb:356:in `block in replace'
# .rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/associations/collection_association.rb:356:in `each'
# .rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/associations/collection_association.rb:356:in `replace'
# .rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/associations/collection_association.rb:41:in `writer'
# .rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/associations/builder/association.rb:118:in `targets='
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:16:in `public_send'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/evaluation.rb:12:in `object'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/strategy/create.rb:9:in `result'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/factory.rb:42:in `run'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/factory_runner.rb:23:in `block in run'
# .rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/notifications.rb:161:in `instrument'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/factory_runner.rb:22:in `run'
# .rvm/gems/ruby-2.1.5/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/controllers/fitness_goals_controller_spec.rb:44:in `block (2 levels) in <top (required)>'
The error references the Target model, a has_and_belongs_to_many (HABTM) association with the Fitness Goal model:
Target(#62887900) expected, got String(#8489780)
The relevant models:
class FitnessGoal < ActiveRecord::Base
has_and_belongs_to_many :targets
end
class Target < ActiveRecord::Base
has_and_belongs_to_many :fitness_goals
end
The join table in schema:
create_table "fitness_goals_targets", id: false, force: true do |t|
t.integer "fitness_goal_id"
t.integer "target_id"
end
Fitness goal params:
def fitness_goal_params
params.require(:fitness_goal).permit(:goal_list_id, :timeframe_id, :start_date, :end_date, { target_ids: [] }, { activity_ids: [] }, :notes, :member_id, :trainer_id)
end
Fitness Goal factory:
FactoryGirl.define do
factory :fitness_goal do
association :goal_list
association :timeframe
start_date Date.current
end_date Date.current + 30
targets ["Lose Fat", "Reduce caloric intake by x%"]
activities ["Walk x steps a day", "Climb x floors a day", "Run x miles a day"]
association :member
association :trainer
notes 'This is a sample note.'
end
end
What am I doing wrong? The application code works as expected in both development and production environments. It appears the problem is somewhere in my set-up for the FactoryGirl object. Implementing the HABTM association is what broke the controller test. How do I fix the issue and get the controller test passing again? Thanks for any help!
You need to change your factory to pass in Target objects rather than strings to that association. So you need to create Target objects (or find them, if they already exist). Change
targets ["Lose Fat", "Reduce caloric intake by x%"]
to
targets { [create(:target, field: "Lose Fat"), create(:target, field: "Reduce caloric intake by x%")] }
The label I used is 'field' because I'm not sure what that field is named, so just use its name instead.

GitLab email notifications not sending

I just recently install GitLab v5.0 on an Ubuntu 12.04 server and am now having issues with email notifications. I can't get GitLab to send any emails of any kind.
I've got my config/environments/production.rb file setup to use sendmail as the transport service:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
And I can manually use sendmail successfully from the shell as described here: http://scratching.psybermonkey.net/2011/03/sendmail-how-to-test-sending-email.html
My config/gitlab.yml file is setup with the following email setting:
email_from: gitlab#myops.com
I've read that it could be a problem with Sidekiq not running so I ran the following command but nothing has changed.. I still can't send emails:
$ sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production
$ ps aux |grep -i sidekiq
git 2791 2.1 4.2 206476 86620 pts/0 Sl 14:45 0:23 sidekiq 2.7.5 gitlab [0 of 25 busy]
Which indicates to me that Sidekiq is indeed running... what else could be the issue here? There doesn't seem to be much documentation on GitLab's wiki regarding email settings unfortunately...
I found the following error being logged in sidekiq.log:
2013-04-24T21:09:01Z 2791 TID-1jaur8 Sidekiq::Extensions::DelayedMailer JID-21bd3ec0f086351088992396 INFO: start
2013-04-24T21:09:01Z 2791 TID-1jaur8 Sidekiq::Extensions::DelayedMailer JID-21bd3ec0f086351088992396 INFO: fail: 0.004 sec
2013-04-24T21:09:01Z 2791 TID-1jaur8 WARN: {"retry"=>true, "queue"=>"default", "timeout"=>30, "class"=>"Sidekiq::Extensions::DelayedMailer", "args"=>["---\n- !ruby/class 'Notify'\n- :new_user_email\n- - 4\n - pSzzULp8\n"], "at"=>1366819034.5969028, "jid"=>"21bd3ec0f086351088992396", "error_message"=>"Couldn't find User with id=4", "error_class"=>"ActiveRecord::RecordNotFound", "failed_at"=>"2013-04-24T15:57:19Z", "retry_count"=>10, "retried_at"=>2013-04-24 21:09:01 UTC}
2013-04-24T21:09:01Z 2791 TID-1jaur8 WARN: Couldn't find User with id=4
2013-04-24T21:09:01Z 2791 TID-1jaur8 WARN: /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:343:in `find_one'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:314:in `find_with_ids'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:107:in `find'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/querying.rb:5:in `find'
/home/git/gitlab/app/mailers/notify.rb:23:in `new_user_email'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:in `process_action'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:459:in `process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:453:in `initialize'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:439:in `new'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:439:in `method_missing'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/extensions/action_mailer.rb:20:in `perform'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:45:in `block (3 levels) in process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:109:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:109:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/timeout.rb:11:in `block in call'
/usr/local/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/timeout.rb:10:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/retry_jobs.rb:49:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/logging.rb:22:in `with_context'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:114:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:114:in `invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:44:in `block (2 levels) in process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:80:in `stats'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:43:in `block in process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/calls.rb:23:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/calls.rb:23:in `public_send'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/calls.rb:23:in `dispatch'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/future.rb:18:in `block in initialize'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/internal_pool.rb:48:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/internal_pool.rb:48:in `block in create'
Any ideas?
This is my entries at the end in /config/environment/production.rb and that is working for me.
Comment out sendmail options and use external SMTP relays
##config.action_mailer.delivery_method = :sendmail ## Comment out this
# Defaults to:
## config.action_mailer.sendmail_settings = {
## :location => '/usr/sbin/sendmail',
## :arguments => '-i -t'
## }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
## SMTP Settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => '10.146.10.90', ## My SMTP Relay/Gateway
:port => 25, ## SMTP Port
:domain => 'gitlab.example.com', ## My Domain
:authentication => :plain, ## Let it be plain as it is inside my LAN
##:user_name => 'gitlab#yourserver.com', ## This is not required as long as
##:password => 'yourPassword', ## SMTP Gateway allows anonymous relay
##:enable_starttls_auto => true ## In LAN
##:user_name => '',
##:password => '',
:enable_starttls_auto => true
}
end
On CentOS, this helped for me:
check your file /home/git/gitlab/config/environments/production.rb (if your running on production, wich is standard)
There you can change your sendmail settings. You should try to remove the -t parameter, wich fixed it for me! Some mailservers don't accept this parameter (check your maillog to be sure)
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i'
}

RailsTutorial: NoMethodError 'permanent' Rake::Test::CookieJar

app/helpers/sessions_helper.rb
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def sign_out
self.current_user = nil
cookies.delete(:remember_token)
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
#current_user = user
end
def current_user
#current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
end
Tests defined in section 9.2.1 Requiring signed-in users are failing:-
At first I was getting sign_in method not found then I added
include SessionsHelper
in spec/utilities.rb file after that I started getting below error, saying no method with name permanent exists in Rake::Test::CookieJar.
Is it due to some Gem version issue.
1) User Pages edit page
Failure/Error: before { sign_in user}
NoMethodError:
undefined method `permanent' for #<Rack::Test::CookieJar:0x007ff12c661e88>
# ./app/helpers/sessions_helper.rb:3:in `sign_in'
# ./spec/requests/user_pages_spec.rb:55:in `block (3 levels) in <top (required)>'
Just ran into the same problem and got it fixed.
It seems they are not referring to the sign_in method in sessions_helper.rb but the the sign_in method in spec/support/utilities.rb
In my case this helper method in utilities.rb had a different name, after renaming it everything worked fine :-)

MMS2R and Multiple Images Rails

Here's my code:
require 'mms2r'
class IncomingMailHandler < ActionMailer::Base
##
# Receives email(s) from MMS-Email or regular email and
# uploads that content the user's photos.
# TODO: Use beanstalkd for background queueing and processing.
def receive(email)
begin
mms = MMS2R::Media.new(email)
##
# Ok to find user by email as long as activate upon registration.
# Remember to make UI option that users can opt out of registration
# and either not send emails or send them to a username+32523#example.com
# type address.
##
# Remember to get SpamAssasin
if (#user = User.find_by_email(email.from) && email.has_attachments?)
mms.media.each do |key, value|
if key.include?('image')
value.each do |file|
#user.photos.push Photo.create!(:uploaded_data => File.open(file), :title => email.subject.empty? ? "Untitled" : email.subject)
end
end
end
end
ensure
mms.purge
end
end
end
and here's my error:
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/runner.rb:48: undefined method `photos' for true:TrueClass (NoMethodError)
from /usr/home/xxx/app/models/incoming_mail_handler.rb:23:in `each'
from /usr/home/xxx/app/models/incoming_mail_handler.rb:23:in `receive'
from /usr/home/xxx/app/models/incoming_mail_handler.rb:21:in `each'
from /usr/home/xxx/app/models/incoming_mail_handler.rb:21:in `receive'
from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:419:in `receive'
from (eval):1
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `eval'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/runner.rb:48
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/xxx/script/runner:3
I sent an email to the server with two image attachments. Upon receiving the email the server runs
"| ruby /xxx/script/runner 'IncomingMailHandler.receive STDIN.read'"
What is going on? What am I doing wrong?
(MMS2R docs)
Please replace
if (#user = User.find_by_email(email.from) && email.has_attachments?)
with
if ((#user = User.find_by_email(email.from)) && email.has_attachments?)