Skip to content

Commit

Permalink
Change some Cucumber tests to use relative timestamp (since we now ha…
Browse files Browse the repository at this point in the history
…ve a restriction on timestamp age)
  • Loading branch information
michaelbaudino committed Apr 2, 2014
1 parent 79b404d commit cbb998e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
27 changes: 27 additions & 0 deletions features/step_definitions/cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
add_fake_web_uri(:get, uri, ['200', 'OK'], body, 'date' => Time.at(new_time.to_i).httpdate)
end

When /^new translations for the api key "([^"]*)" since last fetch with time "([^"]*)" seconds later$/ do |api_key, time_shift|
steps %Q{
When new translations for the api key "#{api_key}" since "#{@timestamp}" with time "#{@timestamp + time_shift.to_i}"
}
end

When /^I have a valid project on localeapp\.com with api key "([^"]*)" and the translation key "([^"]*)"/ do |api_key, key_name|
uri = "https://api.localeapp.com/v1/projects/#{api_key}/translations/#{key_name.gsub(/\./, '%2E')}"
Expand Down Expand Up @@ -78,3 +83,25 @@
"""
}
end

When /^the timestamp is (\d+) months? old$/ do |months|
@timestamp = Time.now.to_i - months.to_i * 2592000
steps %Q{
And a file named "log/localeapp.yml" with:
"""
---
:updated_at: #{@timestamp}
:polled_at: #{@timestamp}
"""
}
end

Then /^translations should be fetched since last fetch only$/ do
steps %Q{
Then the output should contain:
"""
Localeapp update: checking for translations since #{@timestamp}
Found and updated new translations
"""
}
end
30 changes: 6 additions & 24 deletions features/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ Feature: Getting new translations
In order to receive the translations that have been updated since the last check
When I have a valid project on localeapp.com with api key "MYAPIKEY"
And an initializer file
And a file named "log/localeapp.yml" with:
"""
---
:updated_at: 120
:polled_at: 130
"""
And new translations for the api key "MYAPIKEY" since "120" with time "140"
And the timestamp is 2 months old
And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
And a directory named "config/locales"
When I run `localeapp update`
Then the output should contain:
"""
Localeapp update: checking for translations since 120
Found and updated new translations
"""
Then translations should be fetched since last fetch only
And help should not be displayed
And a file named "config/locales/en.yml" should exist
# check the content here
Expand All @@ -26,19 +17,10 @@ Feature: Getting new translations
Scenario: Running update with no initializer file, passing the key on the command line
In order to receive the translations that have been updated since the last check
When I have a valid project on localeapp.com with api key "MYAPIKEY"
And a file named "log/localeapp.yml" with:
"""
---
:updated_at: 120
:polled_at: 130
"""
And new translations for the api key "MYAPIKEY" since "120" with time "140"
And the timestamp is 2 months old
And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
And a directory named "config/locales"
When I run `localeapp -k MYAPIKEY update`
Then the output should contain:
"""
Localeapp update: checking for translations since 120
Found and updated new translations
"""
Then translations should be fetched since last fetch only
And help should not be displayed
And a file named "config/locales/en.yml" should exist

0 comments on commit cbb998e

Please sign in to comment.