Dynamically adjust fixture value in ruby tests
I'm testing my Rails application and a specific part of the project looks at how long ago a user was created. If I write a fixture for this, the only way I can think of right now is to define multiple users with different
Is there a way to dynamically define the
created_at value per test? I'd like to just define one user and each test will pass in a different value for
created_at. If this is not possible, is there a better way I can test this?
See also questions close to this topic
User clicks on forgot password links ends up logging into application if some other user is logged in on same browser
I am using devise for authentication and using devise's default forgot password flow. When user clicks on forgot password link
http://localhost:3000/users/password/edit?reset_password_token=F1XrgcSTYs5nssRZrLqfthen the user logs into application if some other user is already logged into the application on same browser. I understand It happens because devise checks
@current_userin session and
@current_useris the one who is logged in application on that browser.
How can I change the behaviour, User who clicks on forgot password should not login and should be redirected to reset password page.
Best linux text editor for Ruby on Rails programming
I recently started coding in linux and I was wondering if there is any editor that gives easy formatting and syntax highlighting capability. All suggestions will be appreciated. Thanks.
How to fix "undefined method `errors' for nil:NilClass"?
I'm learning book "Agile_Web_Development_with_Rails_5", then in code chapter "Check Out!" I have this error.
NoMethodError in Orders#new Showing /home/chiencong/depot/app/views/orders/_form.html.erb where line #2 raised: undefined method `errors' for nil:NilClass <%= form_with(model: order, local: true) do |form| %> <% if order.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(order.errors.count, "error") %> prohibited this order from being saved:</h2> <ul> Trace of template inclusion: app/views/orders/new.html.erb
Ruby regular expression to get users names after @ symbol
How can I get the username without the @ symbol? That's everything between @ and any non-word character.
message = <<-MESSAGE From @victor with love, To @andrea, and CC goes to @ghost MESSAGE
Using a Ruby regular expression, I tried
username_pattern = /@\w+/
I will like to get the following output
message.scan(username_pattern) #=> ["victor", "andrea", "ghost"]
How to allow just single one e-mail address domain in Google oauth2? (Need to whitelist @company.com only)
I am preparing a gated documentation that will be available only to people with email @company.com which is on Google. I am trying to use as simple solution as possible because I am not an app developer and don't know what I'm doing.
My current solution is a Sinatra app that has a custom
viewspath set to a directory
sitewhere is a static website generated by mkdocs. All routes are defined via the Ruby main.rb with a method that checks if user is logged in before it loads the html content, so that only Google authenticated users get to see the content:
before do # Ensure user has authorized the app unless user_credentials.access_token || request.path_info =~ /^\/oauth2/ redirect to('/oauth2authorize') end
The auth works as I need with the one problem that it will allow any person who has any google account.
From what I found it seems Google oAuth doesn't have a whitelist option, I was hoping creating the credentials from the @company.com account would have the option to only allow users under the same organization but there is no such option.
So what I need is to fetch either the user's domain or the user's email address so that I can hook a method before the rendering starts and either kill it or allow it.
I have successfully used the Gmail API via this service:
service = Google::Apis::GmailV1::GmailService.new
which gives me access to the user's email address via
But it seems this is not a right solution either because it seems to break when there are multiple users logged in at the same time - it kept returning the email of the first logged in user, not the one that was just logging in.
I refuse to believe I am the first ever person on this planet who needs to write gated documentation for people who require SSO because they will not remember any more passwords, but I really cannot find anything about it neither in Google API documentation nor in blogs.
I found in another SO question a mention about "sending the HD parameter" (for hosted domain). According to the docs https://developers.google.com/identity/protocols/OpenIDConnect#hd-param, the hd should be provided when the user is logging in from a hosted domain. I am logging in from a hosted domain but the user credential
user_credentialsdoes not have a hd field.
I am working with the code from this doc page: https://developers.google.com/api-client-library/ruby/guide/aaa_oauth
The full code in pastebin, it is long: https://pastebin.com/rNSe2V48
So my question: How to restrict Google oAuth to a single domain name with HD in Ruby?
Finding an element using placeholder in Protractor?
<input _ngcontent-c6="" formcontrolname="password" name="password" onblur="this.placeholder = 'Password'" onfocus="this.placeholder = ''" placeholder="Password" required="" type="password" ng-reflect-required="" ng-reflect-name="password" class="ng-pristine ng-invalid ng-touched">
What is the best way to find an element:
placeholder = "Enter Username"?
Scenario: find an element using Snippet above User clicks on the
"Enter Name"box, another window pops-up for entering a name.
CasperJS: How to call a subroutine that fires if all test cases pass?
I'm using CasperJS and trying to solve an issue where by I can check if all tests in a suite pass, and thereby do something else? Is there a
casper.test.onevent that can check if all events are passed? If not, how can I wrap around Casper to check that all pass?
Jmeter - waiting for a web grid to load
So we are tasked with doing automation against one of our web applications that has a lot of Ajax calls. We can't seem to get the Test Recorder to work, so right now we are manually writing out those requests. There is a particular web grid that contains about 100 rows x 20 columns of data. We are trying to measure how long it takes to load up that grid. The response data doesn't have any information on the grid too. Do you guys have any idea how to tackle this?