GitLab email notifications not sending - email

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'
}

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

How to setup factory_girl_rails with Rails 5.0.1

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) }

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.

TDD a Hiera hash in Puppet

spec/classes/test_spec.rb
require 'spec_helper'
describe 'test' do
let(:hiera_data) { { :a => 'hello' } }
it { should contain_file('/tmp/hello') }
end
manifests/init.pp
class test {
$a = hiera('a')
file {"/tmp/$a":}
}
results in:
[vagrant#vm-one test]$ rspec
.
Finished in 1.11 seconds (files took 3 seconds to load)
1 example, 0 failures
Problem
TDD a Hiera hash in Rspec-puppet fails.
Attempts
let(:hiera_data) { { :a => 'hello', :b => :c => 'world' } }
results in:
[vagrant#vm-one test]$ rspec
/usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load': /etc/puppet/modules/test/spec/classes/test_spec.rb:4: syntax error, unexpected =>, expecting '}' (SyntaxError)
let(:hiera_data) { { :a => 'hello', :b => :c => 'world' } }
^
/etc/puppet/modules/test/spec/classes/test_spec.rb:4: syntax error, unexpected '}', expecting keyword_end
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
from /usr/local/share/gems/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
and
let(:hiera_data) { { :a => 'hello', :b => 'world' } }
results in:
[vagrant#vm-one test]$ rspec
F
Failures:
1) test should contain File[/tmp/hello]
Failure/Error: it { should contain_file('/tmp/hello') }
Exception:
Hiera type mismatch: expected Hash and got String
# /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera/backend/rspec_backend.rb:47:in `block in lookup'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:76:in `block in datasources'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:74:in `map'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:74:in `datasources'
# /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera/backend/rspec_backend.rb:13:in `lookup'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:206:in `block in lookup'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:203:in `each'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:203:in `lookup'
# /usr/share/ruby/vendor_ruby/hiera.rb:60:in `lookup'
# /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera-puppet-helper/puppet.rb:109:in `block in register_function_hiera_hash'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:164:in `block (2 levels) in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:157:in `block in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/function.rb:42:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/vardef.rb:14:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:11:in `block in evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `each'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/resource/type.rb:127:in `evaluate_code'
# /usr/share/ruby/vendor_ruby/puppet/parser/resource.rb:79:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:233:in `each'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:233:in `evaluate_classes'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions/include.rb:31:in `block in <top (required)>'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:164:in `block (2 levels) in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:157:in `block in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/function.rb:42:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:11:in `block in evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `each'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/resource/type.rb:127:in `evaluate_code'
# /usr/share/ruby/vendor_ruby/puppet/parser/resource.rb:79:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:425:in `evaluate_main'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:131:in `block (2 levels) in compile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:131:in `block in compile'
# /usr/share/ruby/vendor_ruby/puppet/context.rb:64:in `override'
# /usr/share/ruby/vendor_ruby/puppet.rb:244:in `override'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:117:in `compile'
# /usr/local/share/gems/gems/hiera-puppet-helper-1.0.1/lib/hiera-puppet-helper/puppet.rb:16:in `compile'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:34:in `compile'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:95:in `block (2 levels) in compile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:93:in `block in compile'
# /usr/share/ruby/vendor_ruby/puppet/util.rb:161:in `block in benchmark'
# /usr/share/ruby/benchmark.rb:296:in `realtime'
# /usr/share/ruby/vendor_ruby/puppet/util.rb:160:in `benchmark'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:92:in `compile'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:52:in `find'
# /usr/share/ruby/vendor_ruby/puppet/indirector/indirection.rb:201:in `find'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:184:in `build_catalog_without_cache'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:193:in `build_catalog'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:25:in `load_catalogue'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:7:in `block in subject'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `call'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `matches?'
# ./spec/classes/test_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 1.11 seconds (files took 2.76 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/classes/test_spec.rb:6 # test should contain File[/tmp/hello]
and
let(:hiera_data) { { :a => 'hello', :b => 'world','blabla' } }
results in:
[vagrant#vm-one test]$ rspec
/usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load': /etc/puppet/modules/test/spec/classes/test_spec.rb:4: syntax error, unexpected '}', expecting => (SyntaxError)
let(:hiera_data) { { :a => 'hello', :b => 'world','blabla' } }
^
/etc/puppet/modules/test/spec/classes/test_spec.rb:10: syntax error, unexpected keyword_end, expecting '}'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
from /usr/local/share/gems/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
and
let(:hiera_data) { { :a => 'hello', :b => {'world','blabla'} } }
results in:
[vagrant#vm-one test]$ rspec
/usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load': /etc/puppet/modules/test/spec/classes/test_spec.rb:4: syntax error, unexpected ',', expecting => (SyntaxError)
let(:hiera_data) { { :a => 'hello', :b => {'world','blabla'} } }
^
/etc/puppet/modules/test/spec/classes/test_spec.rb:4: syntax error, unexpected '}', expecting keyword_end
let(:hiera_data) { { :a => 'hello', :b => {'world','blabla'} } }
^
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
from /usr/local/share/gems/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
from /usr/local/share/gems/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
Testing restricting to rspec-puppet does not work either:
spec/fixtures/hiera/test.yaml
[vagrant#vm-one test]$ cat spec/fixtures/hiera/test.yaml
---
a: hello
b: world
c: alloallo
fails
[vagrant#vm-one test]$ rspec
F
Failures:
1) test should contain File[/tmp/hello]
Failure/Error: it { should contain_file('/tmp/hello') }
Puppet::Error:
(<unknown>): mapping values are not allowed in this context at line 4 column 4 at /etc/puppet/modules/test/spec/fixtures/modules/test/manifests/init.pp:2 on node vm-one.domain
# /usr/share/ruby/psych.rb:205:in `parse'
# /usr/share/ruby/psych.rb:205:in `parse_stream'
# /usr/share/ruby/psych.rb:153:in `parse'
# /usr/share/ruby/psych.rb:129:in `load'
# /usr/share/ruby/vendor_ruby/puppet/vendor/safe_yaml/lib/safe_yaml.rb:144:in `load_with_options'
# /usr/share/ruby/vendor_ruby/hiera/backend/yaml_backend.rb:18:in `block (2 levels) in lookup'
# /usr/share/ruby/vendor_ruby/hiera/filecache.rb:53:in `read_file'
# /usr/share/ruby/vendor_ruby/hiera/backend/yaml_backend.rb:17:in `block in lookup'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:104:in `block in datasourcefiles'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:76:in `block in datasources'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:74:in `map'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:74:in `datasources'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:99:in `datasourcefiles'
# /usr/share/ruby/vendor_ruby/hiera/backend/yaml_backend.rb:16:in `lookup'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:206:in `block in lookup'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:203:in `each'
# /usr/share/ruby/vendor_ruby/hiera/backend.rb:203:in `lookup'
# /usr/share/ruby/vendor_ruby/hiera.rb:60:in `lookup'
# /usr/share/ruby/vendor_ruby/hiera_puppet.rb:11:in `lookup'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions/hiera.rb:32:in `block in <module:Functions>'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:164:in `block (2 levels) in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:157:in `block in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/function.rb:42:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/vardef.rb:14:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:11:in `block in evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `each'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/resource/type.rb:127:in `evaluate_code'
# /usr/share/ruby/vendor_ruby/puppet/parser/resource.rb:79:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:233:in `each'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:233:in `evaluate_classes'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions/include.rb:31:in `block in <top (required)>'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:164:in `block (2 levels) in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/parser/functions.rb:157:in `block in newfunction'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/function.rb:42:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:11:in `block in evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `each'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast/block_expression.rb:10:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/ast.rb:61:in `safeevaluate'
# /usr/share/ruby/vendor_ruby/puppet/resource/type.rb:127:in `evaluate_code'
# /usr/share/ruby/vendor_ruby/puppet/parser/resource.rb:79:in `evaluate'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:425:in `evaluate_main'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:131:in `block (2 levels) in compile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:131:in `block in compile'
# /usr/share/ruby/vendor_ruby/puppet/context.rb:64:in `override'
# /usr/share/ruby/vendor_ruby/puppet.rb:244:in `override'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:117:in `compile'
# /usr/share/ruby/vendor_ruby/puppet/parser/compiler.rb:34:in `compile'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:95:in `block (2 levels) in compile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:93:in `block in compile'
# /usr/share/ruby/vendor_ruby/puppet/util.rb:161:in `block in benchmark'
# /usr/share/ruby/benchmark.rb:296:in `realtime'
# /usr/share/ruby/vendor_ruby/puppet/util.rb:160:in `benchmark'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:92:in `compile'
# /usr/share/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:52:in `find'
# /usr/share/ruby/vendor_ruby/puppet/indirector/indirection.rb:201:in `find'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:184:in `build_catalog_without_cache'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:193:in `build_catalog'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:25:in `load_catalogue'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/support.rb:7:in `block in subject'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `call'
# /usr/local/share/gems/gems/rspec-puppet-2.1.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `matches?'
# ./spec/classes/test_spec.rb:18:in `block (2 levels) in <top (required)>'
Finished in 0.31976 seconds (files took 2.69 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/classes/test_spec.rb:18 # test should contain File[/tmp/hello]
Looks like all your hash literals are malformed.
Try
let(:hiera_data) do
{ :a => 'hello', :b => { :c => 'world' } }
end
Now hiera('b') should return a value that is a hash.

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?)