Skip to content

Commit

Permalink
Remove key_value helper now that master is 1.9 only and we always use
Browse files Browse the repository at this point in the history
the 1.9 hash syntax in the generators.
  • Loading branch information
rafaelfranca committed Mar 14, 2012
1 parent ec22a2b commit 1ced5ca
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 37 deletions.
4 changes: 2 additions & 2 deletions actionmailer/lib/rails/generators/mailer/templates/mailer.rb
@@ -1,6 +1,6 @@
<% module_namespacing do -%>
class <%= class_name %> < ActionMailer::Base
default <%= key_value :from, '"from@example.com"' %>
default from: "from@example.com"
<% actions.each do |action| -%>
# Subject can be set in your I18n file at config/locales/en.yml
Expand All @@ -11,7 +11,7 @@ class <%= class_name %> < ActionMailer::Base
def <%= action %>
@greeting = "Hi"
mail <%= key_value :to, '"to@example.org"' %>
mail to: "to@example.org"
end
<% end -%>
end
Expand Down
5 changes: 0 additions & 5 deletions railties/lib/rails/generators/app_base.rb
Expand Up @@ -257,11 +257,6 @@ def empty_directory_with_gitkeep(destination, config = {})
def git_keep(destination)
create_file("#{destination}/.gitkeep") unless options[:skip_git]
end

# Returns Ruby 1.9 style key-value pair.
def key_value(key, value)
"#{key}: #{value}"
end
end
end
end
Expand Up @@ -16,7 +16,7 @@
<% end -%>
<td><%%= link_to 'Show', <%= singular_table_name %> %></td>
<td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
<td><%%= link_to 'Destroy', <%= singular_table_name %>, <%= key_value :confirm, "'Are you sure?'" %>, <%= key_value :method, ":delete" %> %></td>
<td><%%= link_to 'Destroy', <%= singular_table_name %>, confirm: 'Are you sure?', method: :delete %></td>
<%% end %>
</table>

Expand Down
5 changes: 0 additions & 5 deletions railties/lib/rails/generators/named_base.rb
Expand Up @@ -180,11 +180,6 @@ def self.check_class_collision(options={})
class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}"
end
end

# Returns Ruby 1.9 style key-value pair.
def key_value(key, value)
"#{key}: #{value}"
end
end
end
end
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.

<%= app_const %>.config.session_store :cookie_store, <%= key_value :key, "'_#{app_name}_session'" %>
<%= app_const %>.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
Expand Down
Expand Up @@ -5,7 +5,7 @@

# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters <%= key_value :format, "[:json]" %>
wrap_parameters format: [:json]
end

<%- unless options.skip_active_record? -%>
Expand Down
Expand Up @@ -3,5 +3,5 @@
#
# Examples:
#
# cities = City.create([{ <%= key_value :name, "'Chicago'" %> }, { <%= key_value :name, "'Copenhagen'" %> }])
# Mayor.create(<%= key_value :name, "'Emanuel'" %>, <%= key_value :city, "cities.first" %>)
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
Expand Up @@ -7,7 +7,7 @@ def index

respond_to do |format|
format.html # index.html.erb
format.json { render <%= key_value :json, "@#{plural_table_name}" %> }
format.json { render json: <%= "@#{plural_table_name}" %> }
end
end
Expand All @@ -18,7 +18,7 @@ def show

respond_to do |format|
format.html # show.html.erb
format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
format.json { render json: <%= "@#{singular_table_name}" %> }
end
end
Expand All @@ -29,7 +29,7 @@ def new

respond_to do |format|
format.html # new.html.erb
format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
format.json { render json: <%= "@#{singular_table_name}" %> }
end
end
Expand All @@ -45,11 +45,11 @@ def create

respond_to do |format|
if @<%= orm_instance.save %>
format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully created.'" %> }
format.json { render <%= key_value :json, "@#{singular_table_name}" %>, <%= key_value :status, ':created' %>, <%= key_value :location, "@#{singular_table_name}" %> }
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
format.json { render json: <%= "@#{singular_table_name}" %>, :status: :created, location: <%= "@#{singular_table_name}" %> }
else
format.html { render <%= key_value :action, '"new"' %> }
format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
format.html { render action: "new" }
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity %> }
end
end
end
Expand All @@ -61,11 +61,11 @@ def update

respond_to do |format|
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully updated.'" %> }
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
format.json { head :no_content }
else
format.html { render <%= key_value :action, '"edit"' %> }
format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
format.html { render action: "edit" }
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
end
end
end
Expand Down
Expand Up @@ -17,16 +17,12 @@ def create_test_files

private

def resource_attributes
key_value singular_table_name, "{ #{attributes_hash} }"
end

def attributes_hash
return if accessible_attributes.empty?

accessible_attributes.map do |a|
name = a.name
key_value name, "@#{singular_table_name}.#{name}"
"#{name}: @#{singular_table_name}.#{name}"
end.sort.join(', ')
end

Expand Down
Expand Up @@ -19,30 +19,30 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase

test "should create <%= singular_table_name %>" do
assert_difference('<%= class_name %>.count') do
post :create, <%= resource_attributes %>
post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
end
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end

test "should show <%= singular_table_name %>" do
get :show, <%= key_value :id, "@#{singular_table_name}" %>
get :show, id: <%= "@#{singular_table_name}" %>
assert_response :success
end
test "should get edit" do
get :edit, <%= key_value :id, "@#{singular_table_name}" %>
get :edit, id: <%= "@#{singular_table_name}" %>
assert_response :success
end

test "should update <%= singular_table_name %>" do
put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= resource_attributes %>
put :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end

test "should destroy <%= singular_table_name %>" do
assert_difference('<%= class_name %>.count', -1) do
delete :destroy, <%= key_value :id, "@#{singular_table_name}" %>
delete :destroy, id: <%= "@#{singular_table_name}" %>
end
assert_redirected_to <%= index_helper %>_path
Expand Down

1 comment on commit 1ced5ca

@sikachu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good bye my key_value. 😢 😢

Please sign in to comment.