Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #73

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Refactoring #73

wants to merge 26 commits into from

Conversation

shah743
Copy link

@shah743 shah743 commented Mar 25, 2015

No description provided.

@wazery
Copy link
Owner

wazery commented Mar 25, 2015

Thanks for your PR, very much appreciated 😄

@wazery wazery self-assigned this Mar 31, 2015
@wazery wazery added this to the 1.1.0 milestone Mar 31, 2015
@sonalkr132
Copy link

I pulled @shah743 refactoring, it has lot of improvements but it introduced many new bugs too. For ex: Migration gives:

NameError: uninitialized constant CacheMigration

I changed CreateRatingCaches to CacheMigration (not sure if thats how things are suppose to be) in lib/generators/ratyrate/templates/cache_migration.rb file. Then it gave:

Index name 'index_rating_averages_on_rateable_id_and_rateable_type_and_rater_id' on table 'rating_averages' is too long; the limit is 62 characters

I just deleted that index from lib/generators/ratyrate/templates/rating_average_migration.rb.
I had used = rating_for_user @project, current_user, "stars" my app but staring it gives error:

NoMethodError - undefined method `qty=' for #RatingAverage:0x000000069150e0

Any clue what might be causing last error?

@sonalkr132
Copy link

I had used = rating_for_user @project, current_user, "stars" my app but staring it gives error:

NoMethodError - undefined method `qty=' for #RatingAverage:0x000000069150e0

Any clue what might be causing last error?

Issue is in lib/ratyrate/model.rb:

def update_overall_average_rating(stars, user, dimension)
    # We need user average rating for all dimensions as will as overall rating form all users of all dimensions ( which they have rated )
    user_average = average_rates_for_user(user) || average_rates_with_user.build(rater: user)
    user_average.avg = user.ratings_given.where(rateable: self).average(:stars)
    user_average.qty = user.ratings_given.where(rateable: self).count
    user_average.save validate: false

    overall     = average_rates || build_average_rates
    overall.avg = Rate.where(rateable: self).average(:stars)
    overall.qty = Rate.where(rateable: self).count
    overall.save validate: false
end

averate_rates don't have qty field in them. Do we need it? It works fine if we just remove those two line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants