I updated from Rails 3.2.3 to 3.2.8 yesterday.
this script worked up until yesterday. now i get this error:
/daily_counts.rb:32:in `<main>': undefined method `each' for 4294:Fixnum (NoMethodError)
top_posters = Load.where("created_at >= '#{today}' AND comments NOT LIKE '%Post%'").count(:all, group: "user_id", order: "COUNT(*) DESC", limit: 8)
output += "Loadmax Totals\n\s\sAll Avaliable Trucks: #{alltrucks}\n\s\sAll Avaliable Loads: #
{allloads}\n\s\sTodays Loads: #{loads}\n\s\sTodays Trucks: #{trucks}\n\nLoadmax Top Posters\n\s\sPostEverywhere: #{posteverywhere}\n\s\sPostOnce: #{postonce}\n"
posters = "\s\s"
LINE 32: Below
top_posters.each do |k,v|
company_name = Company.find(User.find(k).company_id).name unless k.nil?
poster = {
name: company_name,
posts: v
}
poster[:name] = 'MISC' if poster[:name].nil?
posters += "#{poster[:name]}: #{poster[:posts]}\n\s\s"
end
output += posters.chop.chop.chop
output += "\n\s\s"
users = "\s\s"
with the full script. it is exspose to send an email that look like this:
Total Active Loads/Trucks for Today or FutureLast 24 hours Users Logged In: 0
Loadmax Totals
All Avaliable Trucks: 409
All Avaliable Loads: 150799
Todays Loads: 78316
Todays Trucks: 169
Loadmax Top Posters
PostEverywhere: 70374
PostOnce: 2974
AMTransportServices.Inc: 2130
TNT Trucking of the Carolinas LLC: 1099
JM: 425
BOYD: 412
DANDL: 327
bijDHhgvsiKBa: 180
MTB: 177
Ultra Logistics: 131
digihaul#digihaul.com
Last Login Date 2014-06-16
Logins: 23
undefined method `each' for 4294:Fixnum (NoMethodError)
The error is due to your top_posters is 4294 which is an integer because currently it returns a count.So you can't iterate or loop through an integer.
If you want loop through top_posters it should be perhaps an array or a hash.
So you need to fix your query according to your requirements such that the top_posters is an array or a hash.
Related
I try to do an Selenium-Acceptancetest 'Search Result List' with RSpec spec
And my Issue is
It should verify the count of a Button "Detail"
I would be happy to get help for start thinking as a coder; i am a manual tester stil.
My Problem now is:
Method Error
Failure/Error: expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 4)
NoMethodError:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
Sources:
On my way to resolve the issue I tried to modify this and I found this
But its not working
thanksfully remaining!
my Test File:
# coding: utf-8
puts "this is #{File.basename(__FILE__)}"
extend RSpec::Expectations
extend RSpec::Matchers
describe 'SEL' do
before(:each) do
#driver = loadDriver()
end
after(:each) do
#driver.quit
end
it 'test_Page (SEL)' do
#get the page
...
#do input keyword 'Restaurant'
...
#click submit
...
#(Works!) temp Validation1: Is there a "Btn Details" in SearchResultList?
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").displayed?)
#(Works not!) Validation: Are there more than "5 Btns Detail"
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 5)
end
end
Update after first answer:
Given I use
expect(#driver.find_elements(:xpath, "//a[contains(text(),'Details')]")).to be > 0
it hits that error:
Failure/Error: expect(#driver.find_elements(:xpath, "//a[contains(text(),'Details')]")).to be > 0
expected: > 0
got: [#<Selenium::WebDriver::Element:0xa6219008 id="a2a2c83a-e52d-4464-81ec-4fce07ccc0b6">, #<Selenium::We...64378279">, #<Selenium::WebDriver::Element:0x..f90cc8d0e id="de990e21-eecf-48db-873b-76515dba7c3e">]
Given the error message:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
I suspect your issue is a missing bracket. Normal Rspec syntax is
expect(something).to eq(some value).
I would imagine you are missing the closing parenthesis
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 5)
and this should be something more like:
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]")).to be > 5
Although I might guess you need to call a size function on the latter part as well as maybe use find elements. Maybe this will also be useful for you.
I'm trying a fresh installation of prestashop 1.6.1.4, first I got SQL error on query All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead and used the following solution https://www.prestashop.com/forums/topic/480947-error-presta-on-server-2012-r2-sql-error-on-query-all-parts-of-a-primary-key-must-be-not-null/
But now, after install, when I go to admin > catalog I get:
[PrestaShopException]
Root category must be an integer value
at line 212 in file classes/helper/HelperTreeCategories.php
207. }
208.
209. public function setRootCategory($value)
210. {
211. if (!Validate::isInt($value)) {
212. throw new PrestaShopException('Root category must be an integer value');
213. }
214.
215. $this->_root_category = $value;
216. return $this;
217. }
HelperTreeCategoriesCore->setRootCategory - [line 2504 - controllers/admin/AdminProductsController.php] - [1 Arguments]
AdminProductsControllerCore->initContent - [line 189 - classes/controller/Controller.php]
ControllerCore->run - [line 367 - classes/Dispatcher.php]
DispatcherCore->dispatch - [line 58 - admin1/index.php]
$value is empty
Note: I'm trying to install this specific version because I'm debugging:
Cannot save or edit product data in Prestashop 1.6.1.4
The error that you have mentioned appears if the home category is deleted anyhow. Try adding a home category, make it the root category.
For more details you can visit:
http://forge.prestashop.com/browse/NM-606
I am new in twitter development. I am trying to download tweets of important news agency. I used the guidelines provided in http://www.karambelkar.info/2015/01/how-to-use-twitters-search-rest-api-most-effectively. to download the tweets. I know that twitter api has some limitations on the number of requests (180 req per 15 min) and each request can fetch at most 100 tweets. So I expect the following code to get 18K tweets when I run it for the first time. However, I can only get arround 3000 tweets for each news agency. For example nytimes 3234 tweets, cnn 3207.
I'll be thankful if you can take a look at my code and let me know the problem.
def get_tweets(api, username, sinceId):
max_id = -1L
maxTweets = 1000000 # Some arbitrary large number
tweetsPerReq = 100 # the max the API permits
tweetCount = 0
print "writing to {0}_tweets.txt".format(username)
with open("{0}_tweets.txt".format(username) , 'w') as f:
while tweetCount < maxTweets:
try:
if (max_id <= 0):
if (not sinceId):
new_tweets = api.user_timeline(screen_name = username, count= tweetsPerReq)
else:
new_tweets = api.user_timeline(screen_name = username, count= tweetsPerReq, since_id = sinceId)
else:
if (not sinceId):
new_tweets = api.user_timeline(screen_name = username, count= tweetsPerReq, max_id=str(max_id - 1))
else:
new_tweets = api.search(screen_name = username, count= tweetsPerReq, max_id=str(max_id - 1), since_id=sinceId)
if not new_tweets:
print "no new tweet"
break
#create array of tweet information: username, tweet id, date/time, text
for tweet in new_tweets:
f.write(jsonpickle.encode(tweet._json, unpicklable=False) +'\n')
tweetCount += len(new_tweets)
print("Downloaded {0} tweets".format(tweetCount))
max_id = new_tweets[-1].id
except tweepy.TweepError as e:
# Just exit if any error
print("some error : " + str(e))
break
print ("Downloaded {0} tweets, Saved to {1}_tweets.txt".format(tweetCount, username))
Those are the limitations imposed by the API.
If you read the documentation, you will see that it says
This method can only return up to 3,200 of a user’s most recent Tweets.
So, the answer is - normal API users cannot access that data.
The following ActiveRecord calls result in InvalidStatement errors. This occurs when I even provide a hard-coded userid. The session dump shows a session variable "user_id" that has a valid value as well. Can someone help?
def index
#nav = []
#user = B2bUser.find(request.session[:user_id])
#privileges = B2bPrivilege.lookup_all request.session[:user_id]
end
## lookup_all method from b2b_privilege model
def B2bPrivilege.lookup_all current_user_id
return B2bPrivilege.find_by_sql("SELECT b2b_privileges.*, vendors.name AS vendor_name FROM b2b_privileges LEFT JOIN vendors ON vendors.id = b2b_privileges.vendor_id WHERE b2b_user_id = ?", current_user_id)
end
Processing by HomeController#index as HTML
Could not log "sql.active_record" event. NoMethodError: undefined method `name' for nil:NilClass
PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ..."b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LI...
^
: SELECT "b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LIMIT 1
Completed 500 Internal Server Error in 13ms
ActiveRecord::StatementInvalid (PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ..."b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LI...
^
: SELECT "b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LIMIT 1):
app/controllers/home_controller.rb:7:in `index'
I'm trying to build an authentication system for my application
to register the user fills in a form which then submitted calls user#signup
def signup
#user = User.new(params[:user])
#user.password(params[:user][:password])
#user.save
end`
My user model contains
def password(pass)
#password=pass
self.salt = User.random_string(10)
self.hashed_password = User.encrypt(#password, self.salt)
end
When trying to debug, I checked what is contained in my #user hash:
After #user = User.new(params[:user]) the hash contains my parameter exept 'id', 'hashed_password' and 'salt' (plus the timestamps) which are empty
After #user.password(params[:user][:password]) the hash now contains values for 'hashed_password' and 'salt'
#user.save returns
ArgumentError in UsersController#signup
wrong number of arguments (0 for 1)
Stack trace
Started POST "/users/signup" for 127.0.0.1 at Fri Oct 05 14:23:49 +1000 2012
Processing by UsersController#signup as HTML
Parameters: {"user"=>{"last_name"=>"last", "first_name"=>"first", "login"=>"myusername", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"me#gmail.com", "dob(1i)"=>"1980", "dob(2i)"=>"4", "dob(3i)"=>"2"}, "authenticity_token"=>"R8/BNPox9F9rkUXZQ84xjnsplRjqLJYe35EtGjKEAWk=", "utf8"=>"✓", "commit"=>"Create User"}
(0.1ms) begin transaction
(0.0ms) rollback transaction
Completed 500 Internal Server Error in 10ms
ArgumentError (wrong number of arguments (0 for 1)):
app/controllers/users_controller.rb:17:in `signup'
app/controllers/users_controller.rb:16:in `signup'
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (7.8ms)
Any idea?
I'm guessing you have a column called password and/or you have a validation referencing :password.
In that case, the problem is that you've overridden password -- the implicit zero-parameter getter -- with password(pass), a one-parameter setter. You should instead move your setter to password=, and make a getter that always returns nil:
def password
nil
end
def password=(pass)
#password = pass
self.salt = User.random_string(10)
self.hashed_password = User.encrypt(#password, self.salt)
end
As a bonus, this means you can eliminate the explicit password-setting call, since User.new(:password => 'xyz') will call password= automatically.